You are on page 1of 4

8/17/12

LaTeX Notes: Structuring Large Documents

You are here: Robert Dale's Home Page > Resources > Writing Advice for Students > Structuri ng Larg e Docume nts

LaTeX Notes: Structuring Large Documents


As soon as you start to produce documents which have multiple chapters, or documents which are of any decent size, keeping all the source text in one file becomes unmanageable. There are two basic methods you can use for managing large documents; the first is very easy to use but limited in usefulness, so we'll get that out of the way first. In each case the idea is that you have some top level document file and a number of files that get included in this file automatically when you run LaTeX.

1 The Simple Method


Using the simple method, you set up a top level document like this: \ouettl{.} dcmnsye.. .. . \ei{ouet bgndcmn} \nu{isfl} iptfrtie \nu{eodie iptscnfl} .. . \nu{atie iptlsfl} \n{ouet eddcmn} You then segment your text into chunks, which you keep in the files f r t i e t xs c n f l . e and so on; each of these might be a isfl.e eodietx chapter, or a major section. So, f r t i e t xmight look like the isfl.e following (note the use of the macro p o r m a ehere; this isn't standard rganm LaTeX, it's an instance of declarative formatting): \eto{nrdcin scinItouto} Wybc i tebgnigo tm, a ak n h einn f ie pol ue atx fratr epe sd et omte cle \rganm{rf}.. ald pormaenof . When you run LaTeX on the top-level file, the contents of f r t i e t x s c n f l . e and so on will then be read in at isfl.e, eodietx the specified points. This simply makes it easier to handle your text by breaking it into smaller chunks. Note the following: The name of each included file must actually be something. e , tx since LaTeX will automatically add the . e ending when it looks for tx the file. You can have nested calls of this sort---i.e., the file f r t i e t x isfl.e could itself simply be something like: \hpe{nrdcin catrItouto} Teeaetoscin t ti itoutr catr hr r w etos o hs nrdcoy hpe. \nu{isscin iptfrteto} \nu{eodeto} iptscnscin From the previous example you can see that:
web.science.mq.edu.au/~rdale/resources/writingnotes/latexstruct.html 1/4

8/17/12

LaTeX Notes: Structuring Large Documents

Each i p t file {\em isn't} a standalone LaTeX file (in n u ted particular, it doesn't have a \ o u e t t l { . }line or dcmnsye.. the \ e i { o u e t and \ n { o u e t lines). bgndcmn} eddcmn} You can intersperse calls to i p twith other arbitrary text nu and LaTeX commands. This method is limited, in the following ways: 1. If your intention is to avoid printing the whole file every time you format it, you have to explicitly comment out (or delete) the \ n u s ipt you don't want, and this has the consequence that page numbers, section numbers and so on will only take account of the noncommented-out input files (i.e., if you comment out the \ n u { i s f l }in the example above then s c n f l iptfrtie eodie will start on page 1 as Section 1). 2. Worse, if you have cross-references betwen the different input files (e.g., suppose s c n f l includes a \ e that refers to a eodie rf \ a e in f r t i e then LaTeX won't be able to resolve the lbl isfl) references. As a result, this method is best suited to keeping stuff like figures and pictures in separate files, thus making the editing of the actual text less distracting. So, if you have a very complex figure constructed using the LaTeX p c u eenvironment, you might put it into a separate file and then itr include it in the following way: Yucnsefo teral cmlxfgr o a e rm h ely ope iue i Fgr~rfcmlxfgr}ta m ter n iue\e{ope-iue ht y hoy i bte ta yus s etr hn or. \ei{iue bgnfgr} \nu{yiue} iptmfgr1 \ato{yral cmlxfgr}lblcmlxfgr} cpinM ely ope iue\ae{ope-iue \n{iue edfgr}

2 The More Complex Method


The more complex method of managing large documents is similar to the above, except that you use the \ n l d command: icue \ouettl{.} dcmnsye.. .. . \ei{ouet bgndcmn} \nld{isfl} icuefrtie \nld{eodie icuescnfl} .. . \nld{atie icuelsfl} \n{ouet eddcmn} Again, LaTeX looks for f r t i e t x and so on. Now, however, each isfl.e, included file gets its own . u file. This is very important, because you can ax then do the following: \ouettl{.} dcmnsye.. .. . \nldol{eodie icuenyscnfl} .. . \ei{ouet bgndcmn} \nld{isfl} icuefrtie \nld{eodie icuescnfl}
web.science.mq.edu.au/~rdale/resources/writingnotes/latexstruct.html 2/4

8/17/12

LaTeX Notes: Structuring Large Documents

.. . \nld{atie icuelsfl} \n{ouet eddcmn} This tells LaTeX to consult the a xfiles corresponding to each included file, u but only to actually include the text of the files listed in the \ n l d o l icueny line. Because LaTeX looks at the other a xfiles, it knows about section and u page numbers, cross-references, and so on. This means that the output will start at the appropriate page for the text in s c n f l . e , with eodietx appropriate section numbers and so on. Simply by changing the \ n l d o l line and reformatting, you can get different parts of the icueny entire document printed, with all the numbering being that which you would get had you printed the entire document. One potential disadvantage of this method is that, unlike \ n u , each ipt included file will automatically begin on a new page: so you don't want to use this for small arbitrary bits of a document (such as the example of an i p t figure in the previous section), but probably only for individual n u ted sections, or, if they are pretty large and deserve to start on a new page, individual subsections. In a document that consists of multiple chapters, each chapter will start on a fresh page anyway; so you can use this method to keep the text of individual chapters in separate files. For texts where you want to keep individual sections in separate files, one approach is to develop a large document using \ n l d s and then for the final printing change icue them all to \ n u s. So, while a text is being written, each chapter might ipt be an included file which consists of multiple included sections; when any particular sections are printed as a result of being mentioned in the i c u e n yline, each section will start on a new page. For the final text, nldol the section \ n l d s can be replaced by \ n u s so that only the icue ipt chapters start on new pages. Note that you can have multiple files specified in the i c u e n yline, nldol but you have to specify the names separated by commas {\em with no intervening spaces}. So this is okay: \nldol{isbtlsbt icuenyfrti,ati} but this is not: \nldol{isbt lsbt icuenyfrti, ati} From the previous example you can see that you can format discontinuous parts of the text. Don't forget that LaTeX can only take account of a xfiles corresponding to u files that are included, but not mentioned in the i c u e n yline, nldol provided those a xfiles exist, so you have to format each bit (or all the bits u at once by specifying them all in the i c u e n yline) at least once first. nldol

3 Help Make This Document Better


If there are particular things you think this document doesn't contain that it should, or if you disagree strongly with something it contains, or if you think there's something that isn't clear or could be expressed in a better way, please let me know. This document has benefitted from input from Sophia Cormack, Ivan Derzhanski, Dawn Griesbach, Masato Ishizaki, Ewan Klein, Alex Lascarides and Sandy Nelson. It was last significantly revised on 27th March 1993, and since then has only suffered conversion into HTML. [Home|Teaching|Research|Publications|Professional Activities|Resources]

web.science.mq.edu.au/~rdale/resources/writingnotes/latexstruct.html

3/4

8/17/12

LaTeX Notes: Structuring Large Documents

P lea se sen d com m en t s or qu er ies a bou t t h is web sit e t o R ober t .D a le@m q.edu .a u L a st M odif ied: 2 6 M a r ch 2 0 0 6

web.science.mq.edu.au/~rdale/resources/writingnotes/latexstruct.html

4/4

You might also like