19

I have a figure declared like this:

#+CAPTION: Google NGrams Viewer Search
#+NAME: fig:ngrams
[[file:ngrams.png]]

And I'd like to reference it, so that I can write, e.g. Please refer to Figure [[some magic thing here]] and have it output Please refer to Figure 1. I'm using pandoc to convert from .org to .pdf.

I've been trying writing [[fig:ngrams]], as in Please refer to Figure [[fig:ngrams]], but neither Pandoc nor pandoc-citeproc seem to understand that kind of link, and they transform it to Please refer to Figure fig:ngrams.

Jonathan
  • 567
  • 5
  • 20
  • 2
    In Org, one refers to a figure like you suggested, e.g. `Figure [[fig:ngrams]]`. This *works* with `ox.el`, e.g. `ox-latex.el`. If you must use `pandoc` instead of `ox-latex.el` for your PDFs needs, perhaps the right approach would be to file a bug to the Pandoc org-parser maintainers to let them know that it does not support the links syntax fully. – rasmus May 08 '17 at 14:38
  • Your question has a lot of traffic, and the up to date answer is the one with the least votes (from @kostas-tsiligkiris). Could you consider accepting his answer? – pietrodito May 19 '22 at 13:01

3 Answers3

10

Figured it out myself. Turns out with the latest pandoc and pandoc-crossref you can do this:

#+CAPTION: Google NGrams Viewer Searches
#+LABEL: fig:ngrams
[[file:ngrams.png]]

Then:

Please refer to [cite:@fig:ngrams].

Jonathan
  • 567
  • 5
  • 20
  • 1
    No longer working in my installation `: Emacs version: GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20) : of 2020-08-25 : org version: 9.3.7` – Reb.Cabin Oct 26 '20 at 00:59
9

You can also use org-ref. Then you can use ref:ngrams to reference a figure. This works well with LaTeX export. It probably works with pandoc too.

John Kitchin
  • 11,555
  • 1
  • 19
  • 41
  • 4
    Note that after org version 8.3 this needs `(setq org-latex-prefer-user-labels t)` to work: https://emacs.stackexchange.com/questions/38457/name-is-ignored-unless-running-emacs-with-q – xji Jul 31 '18 at 22:20
7

There is another way to reference figures, by using #+NAME: before the figure. For example:

#+CAPTION: Example of the process
#+NAME: fig:theprocess
[[./Images/process.png]]

And later in the place where you need the reference, you add an internal link:

And as can be seen in figure [[fig:theprocess]], the process...

This works nicely with latex export.

  • Are there any keyboard shortcuts that support insertion of such links in a large document (like how reftex behaves with latex documents) ? – Nidish Narayanaa May 19 '23 at 13:39