TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
But what behavior do you want? If one chapter references another with \ref, what do you want it to display when that chapter is distributed separately? – Ben Jan 5 '11 at 19:12
The same that it would display as if it were in the total document. (Each individual chapter file starts the numbering according to its place in the book, so there should not be a conflict.) As in, I would like to store the cross-referencing data within each .tex file so that the others are not necessary. – Akhil Mathew Jan 5 '11 at 19:13
you should use \include and \includeonly, then you can run individuell chapters. See also tex.ac.uk/cgi-bin/texfaq2html?label=include – Herbert Jan 5 '11 at 19:59
have you already considered the filecontents environment and package? – equaeghe Mar 15 '11 at 12:49
up vote 4 down vote accepted

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.,


and your \documentclass command comes after that.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.