hatmatrix
hatmatrix

Reputation: 44952

Emacs org-mode: org to html conversion -- linking to section in a different page?

How can I link to a section of a separate page in org-mode and have it come out linked in the html? For instance, if in a file file.org, I have a label for section X:

** Section X
#+LABEL: sec:X

I can refer to this section with [[sec:X][section X]] within file.org. I can link to file.org with [[file:file.org][link to file.html]] from an external document (and will automatically be linked to the appropriate html file when published). But outside of this document, I can't refer to section X as [[file:file.org#sec:X][link to section X of file.html]] because the section label is converted to numbers (e.g., sec-3_1). So I would have to link to it as [[file:file.html#sec-3_1][link to section X of file.html]], but that assumes I know that the sec:X label will be converted to sec-3_1...

(I am using the default functions used with org-publish-project for the conversion.)

Upvotes: 3

Views: 1419

Answers (1)

jbp
jbp

Reputation: 1621

From: http://orgmode.org/manual/External-links.html#External-links

file:sometextfile::NNN                    file with line number to jump to
file:projects.org                         another Org file
file:projects.org::some words             text search in Org file
file:projects.org::*task title            heading search in Org file

Edit: Better use "CUSTOM_ID" Property like

  file1.org
  -------------

  * Section
    :PROPERTIES:
      :CUSTOM_ID: my_section_link_id
    :END:

Then in file2.org where you want to link to file1.org:Section

  * Sectoin In File2
    - Link to [[file:file1::my_section_link_id][Section]] in File1

I think there is a bug in orgmode 7.4 where if you use "file:file1::#my_section_link_id" it generates incorrect html link, but correct org link. If you use "file:file1::my_section_link_id" generates correct html link, but incorrect org link.

Upvotes: 5

Related Questions