[Tex/LaTex] Include aux file in tex source

auxiliary-filescross-referencing

I have a large book broken into several chapters, each of which reference each other heavily. I would like to be able to distribute individual chapters as self-contained .tex files. I can do this except for the fact that references will not work unless I have the .aux file for the entire book (and I use the xr package for external references). I would thus like to be able to include the large .aux file in the individual chapter files when distributing the individual files. Is there a way I can do this?

Best Answer

You can use either of the environments filecontents or filecontents*. Each of those takes one required argument, the name of the file to be created, and then then it creates that file with the contents of the environment.

The unstarred version adds a few lines of comments at the beginning of the file describing how the file was created, the starred version doesn't add anything to the contents of the environment.

You use these environments before the \documentclass command. That is, you'd beging your latex file with, e.g.,

\begin{filecontents*}{myotherstuff.aux}
\newlabel{\whatever}...
...
\end{filecontents*}

and your \documentclass command comes after that.

Related Question