3. Splitting a Large Document into Several Files
Some people prefer to place each chapter of a large document in a separate file and then input the file into the main document.
There are two basic ways of including the contents of an external file:
and
where <filename> is the name of the file. (The .tex extension may be omitted in both cases.) The differences between the two commands are as follows:
\input
- acts as though the contents of the file were
typed where the
\input
command was. For example, suppose my main file contained the following:and suppose the file myfile.tex contained the following lines:
Here is some sample text.
then the
\input
command behaves as though you had simply typed the following in your main document file:Here is a short paragraph.
Here is some sample text.
\include
- does more than just input the contents of
the file. It also starts a new page (using
\clearpage
) and creates an auxiliary file associated with the included file. It also issues another\clearpage
once the file has been read in. Using this approach, you can also govern which files to include usingin the preamble, where <file list> is a comma-separated list of files you want included. This way, if you only want to work on one or two chapters, you can only include those chapters, which will speed up the document build. LaTeX will still read in all the cross-referencing information for the missing chapters, but won't include those chapters in the PDF file. There is a definite advantage to this if you have, say, a large number of images in your results chapter, which you don't need when you're working on, say, the technical introduction. You can still reference all the figures in the omitted chapter, as long as you have previously LaTeXed the document without the
\includeonly
command.The excludeonly package provides the logically opposite command:
The previous example can now be split into various files:
% arara: pdflatex: { synctex: on }
\documentclass
[oneside]{scrbook}
\title
{A Sample Thesis}
\author
{A.N. Other}
\date
{July 2013}
\titlehead
{A Thesis submitted for the degree of Doctor of Philosophy}
\publishers
{School of Something\\University of Somewhere}
\begin
{document}
\maketitle
\frontmatter
\tableofcontents
\listoffigures
\listoftables
\chapter
{Acknowledgements}
I would like to thank my supervisor, Professor Someone. This
research was funded by the Imaginary Research Council.
\chapter
{Abstract}
A brief summary of the project goes here.
\mainmatter
\include
{intro}
\include
{techintro}
\include
{method}
\include
{results}
\include
{conc}
\backmatter
\end
{document}
If you only want to work on, say, the Method and Results chapters, you can place the following command in the preamble:
This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-02-9).