A method to add external supplementary files with cross-referencing enabled with the xr package
Including external supplementary files in arXiv can be a complicated process, especially when using the xr package for cross-referencing. In this repository, I am showing a simple way to achieve this. Part of the method has been taken from the IncludeSupplement repository with slight modification.
I will divide the whole process into two parts:
- Enabling cross-referencing from the supplementary file
- Adding the supplementary file at the end of the main document
For convenience, I will assume the main tex file is named main.tex and one supplementary file is named supp.tex. You can add more supplementary files as needed.
Before proceeding, download a copy of your source code as a zip file from Overleaf as shown here (this is important!) and extract it to your local computer. Delete the
supp.texfile, as we do not need it. We will need to add several files in this directory and the final contents of this directory will be uploaded on arXiv. For convenience, we will assume that the name of the zip file of the code issource.zipand you have downloaded it into theC:\Users\YourName\Downloads\directory of your Windows machine.
Unless specified, all the changes in the code will be made on the local version you just downloaded, not on the code available on Overleaf.
Enabling cross-referencing using the xr package is one of the most common ways. As I used Overleaf as my LaTeX editor, I followed the instructions as mentioned here and I did not test it in my local environment. However, this should work fine in the local environment as well. To enable cross-referencing, you can follow the steps as follows:
-
Add the
xrpackage in the preamble ofmain.texfile.\usepackage{xr}
-
Add these helper functions in the preamble of
main.texfile.\makeatletter \newcommand*{\addFileDependency}[1]{ \typeout{(#1)} \@addtofilelist{#1} \IfFileExists{#1}{}{\typeout{No file #1.}} } \makeatother \newcommand*{\myexternaldocument}[1]{% \externaldocument{#1}% \addFileDependency{#1.tex}% \addFileDependency{#1.aux}% }
-
Add your supplementary files (the
.texfiles) in the preamble ofmain.texfile.\myexternaldocument{supp} % note that the .tex extention is not included
-
Go to Overleaf, navigate to the
supp.texfile, and compile it. Then download theoutput.auxfile from the automatically generated files as shown here, rename theoutput.auxfile tosupp.aux, and place it into the specified path as mentioned in step 3 of the local source code you downloaded in your local machine.For example, suppose you have the supplementary file
supp.texin the same directory asmain.texand use the same code shown in step 3. In that case, you will place thesupp.auxfile into theC:\Users\YourName\Downloads\sourcedirectory.
There are several ways to add external tex files as PDF in the main file. However, arXiv uses pdfpages package to add the external documents and we will follow the same procedure.
-
Add the following packages in the preamble of the
main.texfile.\usepackage{pdfpages} % include pdfs \usepackage{pgffor} % for loops
-
From the Overleaf editor, go to the
supp.texfile and compile it, download it, rename it tosupp.pdf(or any other name of your like) and then move it to the same directoryC:\Users\YourName\Downloads\source. -
Add the following codes in the preamble of the
main.texfile.% Fix for a pdfpages rotation bug with revtex \makeatletter \AtBeginDocument{\let\LS@rot\@undefined} \makeatother % the name of the supplement PDF file \def\supplementfilename{supp.pdf} % Determine the number of pages % in the supplement file and store \pdfximage{\supplementfilename} \def\numbersupplementpages{\the\pdflastximagepages} \newif\ifarXiv \arXivtrue
Please note that here, the
supp.pdfis the name of the supplementary file you just downloaded from Overleaf and moved into the local source directory. So, do not forget to update the file name in the code if you have named it as something else. -
Add the following code just before the
\end{document}line of your code.\clearpage \ifarXiv \foreach \x in {1,...,\numbersupplementpages} { \includepdf[pages={\x}, fitpaper=true]{\supplementfilename} } \fi
You can comment out the
\clearpageline if you do not want to start your supplementary after the end of the content of your main file.
If you have SVG files in your project, you will most likely encounter an error while arXiv processes your files. Unlike Overleaf, arXiv does not process the SVG files automatically. You will also need to provide the *-tex.pdf and *-tex.pdf_tex files of the SVG files to arXiv. I am curious to know if there are any better ways to do this; however, below, I have provided a simple way to resolve the error. But this process might be tiresome if you have a lot of SVG files.
-
If you run your LaTeX project on the local machine, then the SVG package should automatically create a directory called
svg-inkscape, containing all the required*-tex.pdfand*-tex.pdf_texfiles. All you need to do is copy thesvg-inkscapedirectory along with all of its contents into theC:\Users\YourName\Downloads\sourcedirectory. -
However, if your project is on Overleaf, then go to each of the
texfiles available on your project, compile it, and then download all the*-tex.pdfand*-tex.pdf_texfiles from the generated files as shown here. Then, inside theC:\Users\YourName\Downloads\sourcedirectory, create another directory calledsvg-inkscapeand paste all the downloaded files. Then, your project should be ready to be processed by arXiv.
If you have followed this far, in the directory of your code in your local machine, along with other files, you should have the modified main.tex, the main.bbl, supp.aux and supp.pdf files available. Make a zip file containing all the contents available in the C:\Users\YourName\Downloads\source directory and upload the zip file and then proceed next to compile your code!
When we refer to something of the supplementary file in our main file, it is more convenient, especially for the scientific articles, to let the reader know that the referenced figure is a part of the supplementary file. One common way to do this is to add S before the number of the referenced figure. For example, if I want to cite the second figure of the supplementary file in the main file, writing like Figure S2 would be convenient. Additionally, one may want to change the Figure text shown before the figure number. For example, to indicate a supplementary figure, one may want to write Supp. Figure 1 instead of Figure 1 to distinguish from the main figure 1.
-
To add custom text (
Sin this case) before the figure number, you need to add the following in the preamble of your supplementary file,supp.tex.\renewcommand{\thefigure}{S\arabic{figure}}
-
To add custom text (
Supp. Figurein this case) instead of standardFig.orFigure, you can try adding the following line in the preamble of your supplementary file,supp.tex.\renewcommand{\figurename}{Supp. Figure}
That's it! Thank you for going through this long reading. I tried to describe it as elaborately as possible. For any queries, feel free to reach me at jobayer@ieee.org.