File indexing completed on 2024-11-24 04:34:43

0001 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
0002 <html>
0003 <!-- This document is an unofficial reference manual for LaTeX, a
0004 document preparation system, version of November 2018.
0005 
0006 This manual was originally translated from LATEX.HLP v1.0a in the
0007 VMS Help Library.  The pre-translation version was written by
0008 George D. Greenwade of Sam Houston State University.  The
0009 LaTeX 2.09 version was written by Stephen Gilmore.  The
0010 LaTeX2e version was adapted from this by Torsten Martinsen.  Karl
0011 Berry made further updates and additions, and gratefully acknowledges
0012 using Hypertext Help with LaTeX, by Sheldon Green, and
0013 LaTeX Command Summary (for LaTeX 2.09) by
0014 L. Botway and C. Biemesderfer (published by the TeX Users
0015 Group as TeXniques number 10), as reference material.  We also
0016 gratefully acknowledge additional material appearing in
0017 latex2e-reference by Martin Herbert Dietze.  (From these references no
0018 text was directly copied.)
0019 
0020 Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013,
0021 2014, 2015, 2016, 2017, 2018 Karl Berry.
0022 
0023 Copyright 1988, 1994, 2007 Stephen Gilmore.
0024 
0025 Copyright 1994, 1995, 1996 Torsten Martinsen.
0026 
0027 Permission is granted to make and distribute verbatim copies of
0028 this manual provided the copyright notice and this permission notice
0029 are preserved on all copies.
0030 
0031 
0032 Permission is granted to copy and distribute modified versions of this
0033 manual under the conditions for verbatim copying, provided that the entire
0034 resulting derived work is distributed under the terms of a permission
0035 notice identical to this one.
0036 
0037 Permission is granted to copy and distribute translations of this manual
0038 into another language, under the above conditions for modified versions. -->
0039 <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
0040 <head>
0041 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
0042 <title>\include &amp; \includeonly (LaTeX2e unofficial reference manual (November 2018))</title>
0043 
0044 <meta name="description" content="\include &amp; \includeonly (LaTeX2e unofficial reference manual (November 2018))">
0045 <meta name="keywords" content="\include &amp; \includeonly (LaTeX2e unofficial reference manual (November 2018))">
0046 <meta name="resource-type" content="document">
0047 <meta name="distribution" content="global">
0048 <meta name="Generator" content="makeinfo">
0049 <link href="index.html#Top" rel="start" title="Top">
0050 <link href="IndexDocument.html#Index" rel="index" title="Index">
0051 <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
0052 <link href="Splitting-the-input.html#Splitting-the-input" rel="up" title="Splitting the input">
0053 <link href="_005cinput.html#g_t_005cinput" rel="next" title="\input">
0054 <link href="_005cendinput.html#g_t_005cendinput" rel="prev" title="\endinput">
0055 <style type="text/css">
0056 <!--
0057 /* $Id: latex2e.css 690 2018-09-15 15:20:19Z jimhefferon $
0058    Minor css for latexrefman. Public domain.
0059    Originally written by Jim Hefferon and Karl Berry, 2018. */
0060 
0061 /* So you can style for yourself */
0062 @import url("/css/latexreflocal.css");
0063 
0064 
0065 
0066 a.summary-letter {text-decoration: none}
0067 blockquote.indentedblock {margin-right: 0em}
0068 blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
0069 blockquote.smallquotation {font-size: smaller}
0070 div.display {margin-left: 3.2em}
0071 div.example {margin-left: 3.2em}
0072 div.lisp {margin-left: 3.2em}
0073 div.smalldisplay {margin-left: 3.2em}
0074 div.smallexample {margin-left: 3.2em}
0075 div.smalllisp {margin-left: 3.2em}
0076 kbd {font-style: oblique}
0077 pre.display {font-family: inherit}
0078 pre.format {font-family: inherit}
0079 pre.menu-comment {font-family: serif}
0080 pre.menu-preformatted {font-family: serif}
0081 pre.smalldisplay {font-family: inherit; font-size: smaller}
0082 pre.smallexample {font-size: smaller}
0083 pre.smallformat {font-family: inherit; font-size: smaller}
0084 pre.smalllisp {font-size: smaller}
0085 span.nolinebreak {white-space: nowrap}
0086 span.roman {font-family: initial; font-weight: normal}
0087 span.sansserif {font-family: sans-serif; font-weight: normal}
0088 ul.no-bullet {list-style: none}
0089 BODY {
0090   margin-top: 1em;
0091   margin-left: 1em; /* auto results in two-digit <ol> lost off left */
0092   margin-right: 1em;
0093   margin-bottom: 1em;
0094   /* the idea is to use the whole window, unless it is ridiculously
0095      wide, probably with too-small fonts, too.  */
0096   max-width: 64em;
0097 }
0098 
0099 /* Because we want @math{... @code ...} to be upright, not slanted,
0100    and Texinfo won't fix it. */
0101 code {font-style:normal; font-family:monospace; }
0102 
0103 /* We put a link to our own home page at the bottom. */
0104 div.referenceinfo {font-size:small;}
0105 
0106 -->
0107 </style>
0108 
0109 
0110 </head>
0111 
0112 <body lang="en">
0113 <a name="g_t_005cinclude-_0026-_005cincludeonly"></a>
0114 <div class="header">
0115 <p>
0116 Next: <a href="_005cinput.html#g_t_005cinput" accesskey="n" rel="next">\input</a>, Previous: <a href="_005cendinput.html#g_t_005cendinput" accesskey="p" rel="prev">\endinput</a>, Up: <a href="Splitting-the-input.html#Splitting-the-input" accesskey="u" rel="up">Splitting the input</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="IndexDocument.html#Index" title="Index" rel="index">Index</a>]</p>
0117 </div>
0118 <hr>
0119 <a name="g_t_005cinclude-_0026-_005cincludeonly-1"></a>
0120 <h3 class="section">24.2 <code>\include</code> &amp; <code>\includeonly</code></h3>
0121 
0122 <a name="index-_005cinclude"></a>
0123 <a name="index-_005cincludeonly"></a>
0124 
0125 <p>Synopsis:
0126 </p>
0127 <div class="example">
0128 <pre class="example">\includeonly{  % in document preamble
0129   ...
0130   <var>filename</var>,
0131   ...
0132   }
0133   ...
0134 \include{<var>filename</var>}  % in document body 
0135 </pre></div>
0136 
0137 <p>Bring material from the external file <samp><var>filename</var>.tex</samp> into a
0138 LaTeX document.
0139 </p>
0140 <p>The <code>\include</code> command does three things: it executes
0141 <code>\clearpage</code> (see <a href="_005cclearpage-_0026-_005ccleardoublepage.html#g_t_005cclearpage-_0026-_005ccleardoublepage">\clearpage &amp; \cleardoublepage</a>), then it
0142 inputs the material from <samp><var>filename</var>.tex</samp> into the document,
0143 and then it does another <code>\clearpage</code>.  This command can only
0144 appear in the document body.  The <code>\includeonly</code> command controls
0145 which files will be read by LaTeX under subsequent <code>\include</code>
0146 commands.  Its list of filenames is comma-separated, and it can only
0147 appear in the preamble.
0148 </p>
0149 <p>This example root document, <samp>constitution.tex</samp>, brings in
0150 three files, <samp>preamble.tex</samp>, <samp>articles.tex</samp>, and
0151 <samp>amendments.tex</samp>.
0152 </p>
0153 <div class="example">
0154 <pre class="example">\documentclass{book}
0155 \includeonly{
0156   preamble,
0157   articles,
0158   amendments
0159   }
0160 \begin{document}
0161 \include{preamble}
0162 \include{articles}
0163 \include{amendments}
0164 \end{document}
0165 </pre></div>
0166 
0167 <p>The file <samp>preamble.tex</samp> contains no special code; you have just
0168 excerpted the chapter from <samp>consitution.tex</samp> and put it in a
0169 separate file just for editing convenience.
0170 </p>
0171 <div class="example">
0172 <pre class="example">\chapter{Preamble}
0173 We the People of the United States,
0174 in Order to form a more perfect Union, ...
0175 </pre></div>
0176 
0177 <p>Running LaTeX on <samp>constitution.tex</samp> makes the material from the
0178 three files appear in the document but also generates the auxiliary
0179 files <samp>preamble.aux</samp>, <samp>articles.aux</samp>, and
0180 <samp>amendments.tex</samp>. These contain information such as page numbers
0181 and cross-references (see <a href="Cross-references.html#Cross-references">Cross references</a>).  If you now comment out
0182 <code>\includeonly</code>&rsquo;s lines with <code>preamble</code> and <code>amendments</code>
0183 and run LaTeX again then the resulting document shows only the
0184 material from <samp>articles.tex</samp>, not the material from
0185 <samp>preamble.tex</samp> or <samp>amendments.tex</samp>.  Nonetheless, all of the
0186 auxiliary information from the omitted files is still there, including
0187 the starting page number of the chapter.
0188 </p>
0189 <p>If the document preamble does not have <code>\includeonly</code> then
0190 LaTeX will include all the files you call for with <code>\include</code>
0191 commands.
0192 </p>
0193 <p>The <code>\include</code> command makes a new page.  To avoid that, see
0194 <a href="_005cinput.html#g_t_005cinput">\input</a> (which, however, does not retain the auxiliary
0195 information).
0196 </p>
0197 <p>See <a href="Larger-book-template.html#Larger-book-template">Larger book template</a> for another example using <code>\include</code>
0198 and <code>\includeonly</code>.  That example also uses <code>\input</code> for some
0199 material that will not necessarily start on a new page.
0200 </p>
0201 <p>File names can involve paths.
0202 </p>
0203 <div class="example">
0204 <pre class="example">\documentclass{book}
0205 \includeonly{
0206   chapters/chap1,
0207   }
0208 \begin{document}
0209 \include{chapters/chap1}
0210 \end{document}
0211 </pre></div>
0212 
0213 <p>To make your document portable across distributions and platforms you
0214 should avoid spaces in the file names. The tradition is to instead use
0215 dashes or underscores.  Nevertheless, for the name &lsquo;<samp>amo amas amat</samp>&rsquo;,
0216 this works under TeX Live on GNU/Linux:
0217 </p>
0218 <div class="example">
0219 <pre class="example">\documentclass{book}
0220 \includeonly{
0221   &quot;amo\space amas\space amat&quot;
0222   }
0223 \begin{document}
0224 \include{&quot;amo\space amas\space amat&quot;}
0225 \end{document}
0226 </pre></div>
0227 
0228 <p>and this works under MiKTeX on Windows:
0229 </p>
0230 <div class="example">
0231 <pre class="example">\documentclass{book}
0232 \includeonly{
0233   {&quot;amo amas amat&quot;}
0234   }
0235 \begin{document}
0236 \include{{&quot;amo amas amat&quot;}}
0237 \end{document}
0238 </pre></div>
0239 
0240 <a name="index-nested-_005cinclude_002c-not-allowed"></a>
0241 <p>You cannot use <code>\include</code> inside a file that is being included or
0242 you get &lsquo;<samp>LaTeX Error: \include cannot be nested.</samp>&rsquo;  The
0243 <code>\include</code> command cannot appear in the document preamble; you will
0244 get &lsquo;<samp>LaTeX Error: Missing \begin{document}</samp>&rsquo;.
0245 </p>
0246 <p>If a file that you <code>\include</code> does not exist, for instance if you
0247 <code>\include{athiesm}</code> but you meant <code>\include{atheism}</code>,
0248 then LaTeX does not give you an error but will warn you &lsquo;<samp>No file
0249 athiesm.tex.</samp>&rsquo;  (It will also create <samp>athiesm.aux</samp>.)
0250 </p>
0251 <p>If you <code>\include</code> the root file in itself then you first get
0252 &lsquo;<samp>LaTeX Error: Can be used only in preamble.</samp>&rsquo;  Later runs get
0253 &lsquo;<samp>TeX capacity exceeded, sorry [text input levels=15]</samp>&rsquo;.  To fix
0254 this, you must remove the inclusion <code>\include{root}</code> but also
0255 delete the file <samp><var>root</var>.aux</samp> and rerun LaTeX.
0256 </p>
0257 
0258 
0259 
0260 <hr/><div class='referenceinfo'> <a href='https://latexref.xyz/'> <i>Unofficial LaTeX2e reference manual</i></a></div>
0261 </body>
0262 </html>