11

I'm using Overleaf to write a paper with supplementary material and have been having substantial trouble with separating out Supplemental Material while maintaining references. My MWE is as follows - in Main.tex:

\documentclass{article}

\usepackage[hidelinks]{hyperref}
\usepackage{xr}
\externaldocument{SupplementalMaterial}

\begin{document}

This is text
\begin{equation} \label{eqn}
1+1=2
\end{equation}
Look at Eq.~(\ref{suppeqn})

\end{document}

In SupplementalMaterial.tex:

\documentclass{article}

\usepackage[hidelinks]{hyperref}

\usepackage{xr}

\externaldocument{Main}

\begin{document}

This is text
\begin{equation} \label{eqn}
1+1=2
\end{equation}
Look at Eq.~(\ref{suppeqn})

\end{document}

When I try to compile Main.tex, I get "Warning: No file SupplementalMaterial.aux LABELS NOT IMPORTED" and of course no references properly refer back to their labels. I've tried to find a solution online but frankly have not found an explanation as to where the aux file is supposed to come from, or what exactly it is. I think it's an auxiliary file used to hold information from the "first pass" for documents that take multiple iterations to compile.

How can I get my references to appear properly?

EDIT: Overleaf requires a special set-up to use xr, as detailed here. I was able to use the example linked in that page and port it to another documentclass for my specific uses without much trouble. I will leave this as an update, not an answer, because I do not yet understand why Overleaf requires this approach.

8
  • 1
    xr is for refering to labels in a different document but I suspect here that you simply want the supplementary material at teh end in which case remove xr package and remove \begin{document} \end{document} from suppementalmaterial.tex, and put \input{SupplementalMaterial} before the end of your main document. Commented Feb 7, 2020 at 20:53
  • 1
    I tricked once sharelatex like this: tex.stackexchange.com/questions/252317/… but I don't know if this works on overleaf too. Commented Feb 7, 2020 at 21:02
  • 1
    Now your supplemental material document is a copy of main and references itself via \externaldocument ??? Assuming you didn't mean that (a) use xr-hyper package not xr as you are using hyperref, then make two overleaf projects and save the aux file (in the logs and output menu) from supplemental and upload it as SupplementalMaterial/aux to the project for the main file Commented Feb 8, 2020 at 0:05
  • 1
    Sorry, it looks like I had copied the header from the wrong section. I have edited the question to correct this again. Thank you for pointing out where the aux file is! That will be helpful for me in the future; I had been searching for it.
    – BGreen
    Commented Feb 8, 2020 at 13:47
  • 1
    An alternative trick worked for me is that: if you could compile your tex successfully locally in your own computer, then upload the .aux files for both tex to Overleaf. Then overleaf will compile them correctly with cross-citation.
    – Ingch
    Commented Mar 18, 2022 at 19:12

2 Answers 2

4

You forgot to create a file in the root folder of the project named "latexmkrc" and with content:

add_cus_dep( 'tex', 'aux', 0, 'makeexternaldocument' );
sub makeexternaldocument {
    if (!($root_filename eq $_[0]))
    {
        system( "latexmk -cd -pdf \"$_[0]\"" );
    }
}

This file is used at compile time to create the refer dependencies from the so created aux file. The problem you are experiencing is that at compile time the file aux cannot be found because it is not present, being the above instructions not present.

This should fix your issue, for further info see docs: https://www.overleaf.com/learn/how-to/Cross_referencing_with_the_xr_package_in_Overleaf

3

The set-up described by overleaf did not work for me. I had to make a relative file reference:

\myexternaldocument{./file_to_reference}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .