# Speed up compilation by (pre-)compiling chapters separately?

I am writing a long document with many chapters. They are all included from a root document using \input{chapterX.tex} etc. Compiling everything takes pretty long.

As a workaround to make compilation faster, I typically comment out most \input commands and include only the chapter I'm currently working on. But that's a bad method because then the references to chapters that are not currently included won't work, and the table of contents is almost empty.

I'm wondering if there is a method that does precompilation? Ideally, it would detect that, while I am working on chapter1.tex, nothing in chapter2.tex etc. has changed, and reuse the results from previous compilation runs.

Is that possible? It would be like separate compilation units in languages like C.

-

You can't precompile chapters, but you can use the \includeonly mechanism to ensure that your cross-references and page numbers stay correct while choosing to only include parts of your source.

-
Great, that's pretty much what I wanted. Thanks! –  Frank Aug 18 '10 at 19:49

Extending Joseph's answer a bit: This mean that you use \include and not \input for including the desired chapters. See here for example usage.

-
Oops, missed the use of \input in the question: thanks. –  Joseph Wright Aug 18 '10 at 19:46
Glad to help :). This site really rocks! –  Bran the Blessed Aug 18 '10 at 19:49
And here is a page that explains the crucial difference between \include and \input: web.science.mq.edu.au/~rdale/resources/writingnotes/… . To summarise, each file that you \include will generate a separate *.aux file, and those *.aux files are always read. –  Jukka Suomela Aug 18 '10 at 20:01
–  Joseph Wright Aug 18 '10 at 21:00
@BrantheBlessed, the example has a broken link. –  LWZ Apr 24 '13 at 17:28