In my org file I have something like:

#+NAME: fig:figure

and then I want to reference that figure inside a code block:

    # code ...
    x <- 3
    # more code for fig. [[fig:figure]]

[[fig:figure]] is not a link in the org document and does not get resolved when exported, it simply stays verbatim in the text. Is it somehow possible to make it reference the figure?

1 Answer 1


I think you can do it like this. They key is the mathescape option for minted, and using minted for src block fontification.

#+BEGIN_SRC emacs-lisp
(setq org-latex-minted-options
     '(("frame" "lines") ("linenos=true") ("mathescape")))

#+caption: figure for testing \label{fig-1}

#+BEGIN_SRC ipython
# see figure $\ref{fig-1}$

# Out [1]:
# text/plain
: 4
  • Is it right that this will only work for LaTeX export, i.e., no link-fontification in the org-buffer and the method does not work for other export targets?
    – Tobias
    Apr 30, 2019 at 14:37
  • that works, pretty cool! Is it possible to set the use of minted file local?
    – gdkrmr
    Apr 30, 2019 at 16:10
  • I think you can use org-latex-listings to locally control which package is used. You want to set it to 'minted Apr 30, 2019 at 18:38
  • Also this will only affect LaTeX exports. It won't fix anything in the org-buffer, or work for other export backends. Apr 30, 2019 at 18:38
  • an even better way is the option texcl, it only works in comments but does not switch to the math font!
    – gdkrmr
    May 2, 2019 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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