# arXiv: post supplementary files using external document and xr

I have two documents in LaTeX, one called main.tex and the other supplement.tex. They are both linked together by the xr package and compile without error. (They have to be compiled in the order: pdflatex on main followed by pdflatex on the supplement and then pdflatex on the main again to complete the cross-referencing. Is there a way to put this on arXiv and letting the compiler there know that pdflatex has to run a few times on each docment? Many thanks! Should one put up the .aux files also in that case?

You can workaround a problem. Take your file.aux, create xx.tex and upload it to arxiv along with your latex file. the xx.tex is:

\begin{filecontents}{file.aux}
The content of file.aux
\end{filecontents}


\makeatletter\@input{xx.tex}\makeatother


This way your latex file will create the file.aux that you can use with xr and \externaldocument

• This answer should be more highly publicised. Other answers (around the internet) seem to basically say "no, it can't be done" or give a more complicated answer that doesn't always work with the fact that arXiv only runs through once. I would +10 if possible! Nov 5 '19 at 10:57
• It works! I Just add a clarification, since I was a bit confused at first. Here file.aux refers to the main.aux in the question, and your latex file is the supplement.tex. So you take the generated aux file from your main tex file and add it to the supplement. Jul 1 '20 at 19:25
• This trick is really good and applicable to any other submission files, e.g., file.toc (for Table of Contents). Some packages (e.g., pagesel) forces ArXiv NOT to generate the required files like .aux, .toc, etc. Sep 7 '20 at 21:26
• What about xx.tex. Can this be anything, or does it specifically need to be xx.tex? What if you also reference the main document in supplemental info? Apr 12 at 20:46
• @Sterling I'm not sure, sorry! I had trouble with zref. Basically, it seems that all these packages---xr, xr-hyper, zref---are extremely buggy. I found lots of issues. The method I post (tex.stackexchange.com/a/592673/81928) doesn't wipe internal hyperlinks. Eg, I may have "Section 1" hyperlinked in both documents, but it knows which is which. Apr 14 at 7:49

I would upload the compiled supplement.pdf, and supplement.aux with main.tex so the arXiv compiler can extract all the labels used in supplement.tex (via xr) when building main.tex, that should compile fine.

However I really would suggest including the supplementary in the main PDF (e.g. combining the tex sources or appending supplement.pdf using pdfpages) as finding supplementary through downloading the source is a pain and can leave the supplement's existence poorly advertised.

• I tried uploading supplement.aux and main.aux since both documents cross-reference each other, but to no avail. Nov 12 '17 at 14:13
• Also, I am not sure how pdfpages works but not sure that the cross-referencing can work as is being suggested. Note that both main.tex and supplement.tex reference each other and it works very well for my purposes. Nov 12 '17 at 14:20
• The arXiv wants a single file to compile to produce the paper, anything else should be included as an ancilliary file so I am suggesting upload the pre-compiled supplement.pdf and as long as supplement.aux is bundled with main.tex all references should appear correctly in the produced main.pdf. Are you looking for hyperlinking to work? This would be much more of a problem. Nov 14 '17 at 14:23
• ArXiv now seems to complains about uploading .aux files that have a corresponding .tex file Apr 13 at 21:01

the xr package (and packages like it, such as xref that rely on having an external aux file present) don't work in arXiv's autotex engine. You'll need to re-work you citations between the two documents to not be cross-referenced from the same aux file.

I had a similar situation: I had give papers in total, all referencing each other! I uploaded them all to arXiv on the same day. For simplicity, let's pretend I just had two. I had the following code on my preamble.

\usepackage{xr}
%\externaldocument{Paper1}
\externaldocument{Paper2}


Here I assume we're working in Paper1 so I commented it out because you don't need to self-reference with xr. Indeed, if you do, then it will give you multiple defined labels warnings. Comment out the second line in Paper2.

Very importantly, you must make sure that labels are referenced in a unique way across all documents. Eg, don't use \ref{sec:intro}. I used \label{sec-p1:intro} and \label{sec-p2:intro}. I believe xr package has an optional arugument. I am not sure of the exact details, but if you write something like \externaldocument[p2:]{Paper2} then any label label from Paper2 will be imported as p2:label. Personally I preferred writing in the paper number manually, but either option is fine.

The following is my understanding of what happens. It might not be 100% accurate.

• If the current document is Paper1.tex, then latex creates Paper1.aux with all the label references. This file is used for the cross-references. Eg, if you type \ref{label} then it looks in Paper1.aux for the label label and, if it exists, prints out the appropriate thing.

• The xr package makes latex look not just in doc.aux but in all the referenced documents. So above it will look in both of Paper1.aux and Paper2.aux.

• Importantly, the xr package does not create Paper2.aux. We are running latex on Paper1.tex, so it only changes Paper1.???.

Now I describe how to do the arXiv submission.

• Make a new folder, arXiv_Submission_Paper1 and move your Paper1.tex file to this folder, along with anything else you need to compile---pictures, premable, etc.

• Incidentally, it is good practice to make a full copy of your submission and place it in a folder which you don't edit. This way you can see in the future exactly what you uploaded.

• Also, place Paper2.aux in this folder. You don't need Paper2.tex---you aren't going to compile that. You only need the .aux file.

• Now just upload Paper1, uploading Paper1.tex and Paper2.aux, along with anything else you may need! The xr package reads the Paper2.aux file exactly as you want it to.

• Swap the numbers 1 and 2 to do the same for Paper2.

This can easily be extended to more papers by just uploading more .aux files. If you have lots, you could create a subfolder called aux_files and use \externaldocument{aux_files/paper#}.

Alternatively, you can just merge all the other .aux files, eg Paper1.aux, Paper2.aux, Paper3.aux, Paper4.aux and Paper5.aux into aux_all.aux. You then just use \externaldocument{aux_all}. They might seem scary because of the .aux file extension. But they're just plain text files. You can edit them with Notepad, for example. Make sure to include a linebreak at the end of each file! You will get multiple defined labels warnings if you include Paper1.aux. It's up to you whether you are happy with this warning---it is only a warning and will not stop tex from running.

I can confirm that this worked on arXiv both in November 2019 (first upload) and in February 2021 (revision). The arXiv system changed significantly between these two times. arXiv used to just run latex once. This is one reason why you need to upload a .bbl file, rather than the .bib. These days arXiv will run latex many times. The above method worked, unchanged, both times.

Just for reference (and because I was proud of myself for finding this), I found another way taking inspiration from Overleaf's instructions to use xr. This can equally be achieved by adding the following to the head of your main tex file:

\usepackage{xr}
% The following is to make it work on Arxiv. The trick is to include the
% build/*.aux files in the zip, they are then hidden to Arxiv which does not
% delete them.
\makeatletter
\newcommand*{\addFileDependency}[1]{ % argument=file name and extension
\typeout{(#1)}
\IfFileExists{#1}{}{\typeout{No file #1.}}
}
\makeatother

\newcommand*{\myexternaldocument}[3][SI]{%
\externaldocument[#1]{#2/#3}%

and including the directory where you left your .aux file (here build/) when you upload files during your submission.
• @Sterling Then you simply add the same header in .tex file of the SI, simply changing the referencing prefix SI (if you want) and SI-filename to the name of the .tex file of the main text, without forgetting to include the corresponding .aux file in the build/ directory (I've just tested it, it works for me). Apr 13 at 9:05
• Actually I realise now to simply answer this question you only need to add \externaldocument[SI]{build/SI-filename} to the head, defining \myexternaldocument is only something I needed to make xr work both on Overleaf and locally, which is outside the scope of this question. Apr 13 at 9:26