About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Smile for the Camera: a new cybercrime short story ebook.


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:

\input{<filename>}

and

\include{<filename>}

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:

Here is a short paragraph.

\input{myfile}

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 using

\includeonly{<file list>}

in 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:

\excludeonly{<file list>}

The previous example can now be split into various files:

Listing 2 (thesis.tex):

% arara: pdflatex: { synctex: on }
% 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}

Listing 3 (intro.tex):

\chapter{Introduction}
\label{ch:intro}

Listing 4 (techintro.tex):

\chapter{Technical Introduction}
\label{ch:techintro}

Listing 5 (method.tex):

\chapter{Method}
\label{ch:method}

Listing 6 (results.tex):

\chapter{Results}
\label{ch:results}

Listing 7 (conc.tex):

\chapter{Conclusions}
\label{ch:conc}

If you only want to work on, say, the Method and Results chapters, you can place the following command in the preamble:

\includeonly{method,results}


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-02-9).

© 2013 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs