# External links to figures in org-mode

I would like to be able to link specific figures from other documents. Basically the function of the xr package in LaTeX where it doesn't necessarily give you an actual link that will take you outside of the document but just takes care of printing the correct figure label automatically.

For example I have my main manuscript.org and a supplemental_info.org and I reference the figures in supplemental_info.org in the manuscript.org. I define all of them like:

#+NAME: fig:my-fig
[[./figures/figure.pdf]]


I tried referencing them using [[file:supplemental_info.org::fig:my-fig]] which didn't work.

I also can't use the xr package directly (i.e. \ref{fig:my-fig}) because org-mode mangles the labels when it exports!

So is there a way to do this prescribed by org-mode?

Alternatively, is there a way to force org-mode to export the #+NAME: values as the label values?

This org-file worked for me:

#+latex_header: \usepackage{xr}
#+options: toc:nil

In Figure ref:si-some-fig you can see it.


with this supplemental-org file:

#+options: toc:nil

In the beginning.

#+name: some-fig
#+caption: caption
[[./test.png]]
See Figure  ref:some-fig.

#+BEGIN_SRC emacs-lisp
(org-latex-export-to-latex)
(shell-command "latexmk -shell-escape -pdf /Users/jkitchin/vc/journal/2018/07/01/supplemental-info.tex")
#+END_SRC

#+RESULTS:
: 0


The ref link (if you use org-ref) will be red, because it doesn't recognize the label in the current document. For it to compile correctly, you have to have built the supplemental-info.org file in a way that results in a supplemental-info.aux (I used latexmk) file before you can build the manuscript file.

I am not sure what you mean by org mangles the names. You might need to set org-latex-prefer-user-labels to t.

From John's excellent answer above, I realized it was due to the lack of the .aux file. To force keep the .aux file (and .bbl) in latex exports, I did the following:

;; choose temporary files to delete
;; removed aux, bbl - need them
(setq org-latex-logfiles-extensions (quote ("lof" "lot" "tex~" "idx" "log" "out" "toc" "nav" "snm" "vrb" "dvi" "fdb_latexmk" "blg" "brf" "fls" "entoc" "ps" "spl")))