# Making a series of child TeX files and including them as "chapters" in a parent file?


and the standalone package. I'm not sure I'll be able to do what I want with these.

Each child document needs to stand on it's own, with it's own preamble, and table of contents, etc. But they should be included in a master document with a global table of contents that ignores/copies all preambles.

Below is example code for one of the children files.

\documentclass[11pt]{article}
\usepackage{amsmath, amsfonts,amssymb,latexsym, multirow}
\usepackage{fullpage, graphicx, subfig, float, hyperref, enumerate}
\usepackage[parfill]{parskip}
\usepackage{pdflscape}%for large figures
\usepackage{cancel}

\hypersetup{backref,
pdfpagemode=FullScreen,

\renewcommand{\dag}{^\dagger}
\renewcommand{\d}{\text{d}}
\newcommand{\D}{\text{D}}
\newcommand{\bra}{\langle}
\newcommand{\ket}{\rangle}

\newcommand{\comment}[1]{}

\newcommand{\p}{\partial}
\newcommand{\eq}[1]{\begin{align*}#1\end{align*}}

\begin{document}

\noindent \fbox{
\begin{minipage}{6.4in}
\medskip
\textbf{Book} \hfill \textbf{Author}
\begin{center}
{\Large Chapter \#} \\[3mm]
\end{center}
\today \hfill Subauthor
\medskip
\end{minipage}
}

\bigskip
\tableofcontents
\newpage
\section{}
\subsection{}
\end{document}

• The combine package may help. See tex.stackexchange.com/questions/119415/…. You could also consider a master document with include and includeonly. Jun 19, 2013 at 17:43
• Doesn't that still require that I build up my preamble manually? Jun 19, 2013 at 17:48
• Both the methods I suggested above allow you to create a preamble once and use it in several contexts. Jun 19, 2013 at 17:56
• But this is not what I need though. The preamble might vary across chapters, and when I compile a single chapter - it will have its own table of contents. There should be a global table of contents when I compile all chapters at once, rather than individual ones. \include and \includeonly will allow for a global preamble, but I can only compile a master document, not individual ones. Jun 19, 2013 at 18:04
• Look at the combine package ctan.mackichan.com/macros/latex/contrib/combine/combine.pdf. It should be flexible enough to meet your needs. Jun 19, 2013 at 18:18

There are packages to do that kind of combination but if you are worried about unknown artefacts from the command redefinitions you can simply use

\ifx\p\undefined
\documentclass[11pt]{article}


. . .

\fi
\begin{document}


Then when processed on its own the document will work as normal but in a larger document that already has those definitions loaded (and in particular \p defined you can use

{\def\document{}\def\enddocument{}\input{file-1}}


Not related to the inclusion question but the boxed heading is lager than the page:

Overfull \hbox (36.87251pt too wide) in paragraph at lines 29--40


The subfiles package does exactly what you are looking for. There are is a great documentation on Overleaf even with live examples. The main document includes the child files as this:

\documentclass{book}
\usepackage{subfiles}
% global preamble
\begin{document}
\subfile{childA}
\subfile{childB}
\subfile{childC}
\end{document}


The child files can be compiled individually and even have their own preamble.

\documentclass[main.tex]{subfiles}
% individual preamble
\begin{document}
content
\end{document}


Also cross-references between the files are supported.