Links from orgmode to any text file

Hyperlinks are very useful in orgmode files. You can link from an orgmode file to some internal heading (i.e. in that same file) or some external file. You can even link to a BibTeX entry, to an email, a webpage, a remote file via SSH, and many other objects.

Today, I needed to link from an orgmode file to a subsection in a LaTeX file. At first I thought this were impossible because LaTeX files are not officially supported by orgmode links (as BibTeX files). I thought the best I could do was to link to the LaTeX file, and then I would have to search for the subsection in the buffer. I was wrong. Hyperlinks in orgmode can take a very general form to any text file that will be open in Emacs. If you put ::NNN after a file name in the link, Emacs will open the text file (or switch to the buffer if it was already opened) and jump directly to the line numbered NNN. If you put ::sometext instead, Emacs will search for the string <<sometext>> or sometext (the first has higher priority) in the file and jump to the first occurrence. Using this feature, it is easy to link to a label, or any text, in a LaTeX file. For example, if the section I want to link to has label sec:section-1, I can use the following hyperlink:

[[file:mylatex.tex::\label{sec:section-1}]]

Note that if I simply use the search text sec:section-1 then Emacs could jump to a wrong position, i.e. any cross-reference to the section that appears before the section itself. If I want to use a simpler search text but still want to jump to the correct position, I can mark the section with <<sec:section-1>> (or any unique label). For example, I can write in the LaTeX file:

%<<sec:section-1>>
\section{My Section}
\label{sec:section-1}

and use the link

[[file:mylatex.tex::sec:section-1]]

Or I can use

%<<my awesome section>>
\section{My Section}
\label{sec:section-1}

and use the link

[[file:mylatex.tex::my awesome section]]

I plan to use this wonderful feature in organizing my thesis’ LaTeX files. Basically, I will write each chapter (sometimes section) in a separate file. I will create an orgmode file where I put links to the LaTeX files, TODO tasks, notes, etc. If a note or task applies to a specific section in a LaTeX file, I will put a link so that I can quickly jump to it. Furthermore, because orgmode hyperlinks can be used globally in any non-orgmode file, I can put hyperlinks directly in LaTeX files to link related parts (which may reside in different files).

Advertisements
This entry was posted in Computer and tagged . Bookmark the permalink.

One Response to Links from orgmode to any text file

  1. Pingback: Domenico Prattichizzo & SIRSLab's Folks Blog » Links from orgmode to any text file | Truong’s Weblog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s