# Combine .tex file with .aux files to produce a single self-contained .tex file

I have submitted a paper to PLoS Computational Biology and it has been accepted. The paper has three supporting text pieces, which PLOSCB requires to be separate files. So, I split my paper into four files, let's call them paper.tex, S1.tex, S2.tex, S3.tex. There are cross-references from paper.tex to each of the S*.tex documents. I used the xr package for these. This works fine, but requires that S*.aux files be present during the compilation of paper.tex. So, I uploaded paper.tex and the S*.aux files to the journal. I just got an email from them saying:

Please ensure that you have provided a single, cohesive .tex file for your LaTex submission. Please send us one complete tex file without the aux files.

How can I do that? Is there any way to sort of paste the S*.aux files into paper.tex so that it compiles and correctly resolves cross-references?

• are you sure they mean you to combine the aux (you can do that if you must) I would read it as saying that you should not have separate \input files (eg for chapters) and do not send the aux file. oh but xr may be difficult for them. stick each of the aux files in a filecontents environment in your main document so they only need to handle a single tex file but the aux will be there when it is used. Jul 21 '21 at 21:50
• I don't understand how "PLOSCB requires to be separate files" and "Please send us one complete tex file" go together. Jul 21 '21 at 21:54
• @Teepeemm: They don't require .tex source for the supporting text files. Those can be submitted as PDFs. Jul 21 '21 at 22:02
• @DavidCarlisle: "stick each of the aux files in a filecontents environment in your main document so they only need to handle a single tex file but the aux will be there when it is used. " That sounds something like an answer, but it doesn't make any sense to me in this brief form. Would you mind writing that up as an answer to this question? Jul 21 '21 at 22:05
• @DavidCarlisle: "are you sure they mean you to combine the aux (you can do that if you must)" No, I am not sure of that. I have given you all the information they gave me. Pasting the .aux files into the .tex file was my idea, not their suggestion, and I wrote it as a question because I have no idea if that's even a feasible solution. Jul 21 '21 at 22:13

## 2 Answers

In your main file you can use

\begin{filecontents}{S1.aux}
... contents here
\end{filecontents}
\begin{filecontents}{S2.aux}
... contents here
\end{filecontents}
\documentclass{article}
\usepackage{xr}
\externaldocument{S1}
\externaldocument{S2}
...


Although @DavidCarlisle's answer works fine on its own terms, it turned out not to solve my problem. On further communication, I learned that PLoS forbids the use of the \externaldocument command.

So, what I ended up doing, which seems to work, was to grep out the lines of the S*.aux files that begin \newlabel{ and paste them into paper.tex. I put them in the preamble where I previously had the \externaldocument commands.