I'm experimenting with the following approach. Let the master file contain this:
\documentclass{...}
\usepackage{newclude}
\def\inmaster{1}
\ifdefined\subonly\includeonly{\subonly}\fi
\begin{document}
\include{subone}
\include{subtwo}
\end{document}
and the subfiles begin like this (no preamble or \begin{document}
):
\ifdefined\inmaster\else\def\subonly{\jobname}\input{master}\fi
\chapter{Chapter Name}
...
Finally, make all the .aux
files symbolically linked, e.g. with the bash command
for f in *.tex; do ln -s master.aux ${f%.tex}.aux; done
Now the master file can be compiled on its own to produce output containing all the chapters, and likewise each individual chapter file can be compiled on their own to produce output containing only that chapter (but which will still be correctly numbered and can refer to labels in other chapters).
This has the advantage that once it's set up, each .tex
file can be compiled just like normal; no fancy makefiles, scripts, or compilation tools are required. However, it has the disadvantage of requiring the initial setup of symbolic links (and in particular of requiring an OS that supports them). But one can trade-off the symbolic links for a slightly more complicated compilation, compiling each chapter file with e.g.
cp master.aux chapterone.aux && pdflatex chapterone
Either way, a script could easily loop over the chapter files and compile them all.
hyperref
package, that is perhaps less work.