Latest news 2024-03-02: Ebook sale (3rd–9th March 2024): short story cybercrime fiction Unsocial Media free; short story noir crime fiction I’ve Heard the Mermaid Sing free; crime fiction novel The Private Enemy US$1.99; illustrated children’s story The Foolish Hedgehog US$0.99. For further details, see latest blog post.

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:




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:

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.


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.

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 }

\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}




I would like to thank my supervisor, Professor Someone. This
research was funded by the Imaginary Research Council.


A brief summary of the project goes here.









Listing 3 (intro.tex):


Listing 4 (techintro.tex):

\chapter{Technical Introduction}

Listing 5 (method.tex):


Listing 6 (results.tex):


Listing 7 (conc.tex):


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

© 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