This is similar to Org export to latex and HTML references, but for equations.

I like to use LaTeX math snippets in my org-files, as in

* The Quadratic Equation
The roots of $ax^2 + bx + c$ are given by
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}

According to Equation \ref{eq:1}, ...

When I export to LaTeX, the \ref{eq:1} correctly turns into a hyper link to the equation. But I want to achieve the following additional behavior:

  1. Inside the org file, I can click the text \ref{eq:1} (the text doesn't have to be \ref{eq:1}, I just want a hyperlink) and be taken to to the equation. This functionality is present for headers, as in [[The Quadratic Equation]] becomes clickable in Org mode.

  2. When I export to HTML, I want to the references to be kept (actually, the label (1) doesn't even show up in HTML export).

Is there a way to accomplish this?

  • Technically... wrapping the equation into #+begin_src latex ... #+end_src and then, if you place #+name: eq:1 and #+label: eq:1, you should be able to reference this block the way you want, i.e. using a link [[eq:1][first equation]], but for some reason it doesn't work for me (but it could be due to the changes I've made).
    – wvxvw
    Aug 21 '15 at 9:27
  • @wvxvw If you changed the behaviour through advices only you can test without changes via emacs -Q. Naturally, this does not help if you changed the sources directly.
    – Tobias
    Aug 21 '15 at 12:39
  • @Tobias nah, I remember patching Org code, specifically something related to it inserting \label{} into verbatim environment, but I'd need to dig up my changes to make sure it's my fault. It would help me though, if someone could confirm that the suggested way with #+name etc works.
    – wvxvw
    Aug 21 '15 at 13:13
  • @wvxvw At html-export I get <pre>/</pre>-Tags around the equation environment. Therefore, firefox shows the source and not the equation.
    – Tobias
    Aug 21 '15 at 13:26
  • @Tobias, right, I completely forgot about it, you'd also need the by-backend macro from here: orgmode.org/worg/org-contrib/babel/languages/…
    – wvxvw
    Aug 21 '15 at 13:38

I had to run some test, but I managed to run a small file that exports correctly to both latex and HTML, I tested only in org 8.2.10, but it should work on other versions.

The answer is actually the same as in Org export to latex and HTML references

Here I have a small example

*  This is a latex experiment
so with the text...
#+NAME: code:1
#+BEGIN_SRC shell-script
echo hello world 
[[code:1]] is a reference to src block

#+NAME: eqn:1
    f(x) =  \sum\limits_0^\infty(f^{(n)}(x)|_{x=0} \cdot x)

And this is an equation [[eqn:1]]
  • Nice, this works for me out of the box.
    – Tobias
    Aug 22 '15 at 8:37
  • This works for me too in LaTeX, but it doesn't work for "out of the box" in HTML, since the equation doesn't even have a number (some Mathjax option isn't being set, probably). Now if only RefTeX would support this, but that's another question. I will wait a couple more days before accepting, to see if anyone else will chime in :)
    – Kevin
    Aug 23 '15 at 5:56
  • I accepted, but see my own answer below (later version of Org has support out of the box).
    – Kevin
    Aug 25 '15 at 0:23
  • I get "undefined references" in LaTeX; doesn't work for me with Emacs 24.5.1 (Org mode 8.2.10)
    – Reb.Cabin
    Mar 19 '16 at 2:57
  • 2
    Can this somehow be extended to multi-line AMS environments like align and subequations, where the label is specific to parts of the equation?
    – kdb
    Jun 6 '18 at 10:18

Actually, it seems that Org mode 8.3.1 has built-in support for what the question is asking; label and ref work out of the box.

This requires one to update Org mode through the package manager; afterwards, stick (package-initialize) near the top of the initialization file.

EDIT. This does not allow you to click the \ref{...} and go to the label. For that, please see the accepted answer above, or use org-ref.

  • 1
    But you don't get to click on \ref{.} to go to \label{.}, right?
    – rvf0068
    Sep 2 '15 at 23:45
  • No I cannot. For that, you have to use either Joafigue's answer above or see my comment above regarding github.com/jkitchin/org-ref. I will edit my answer to reflect that.
    – Kevin
    Sep 3 '15 at 2:01

As is described in Internal links.

You can use <<id>> to set your target id and use [[id]] or [[id][description]](You can use C-c C-l to insert this) to find your target.

This works for me while exporting to HTML.

  • But does it work with LaTeX equations? Oct 5 '21 at 12:50
  • 1
    This is an alternative solution. You can put <<id>> before equation.
    – Ynjxsjmh
    Oct 6 '21 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.