6

I want to build a big PDF of multiple TeX files which will all have the same preamble. They'll have \newcommand and \renewcommand as well as \usepackage and \documentclass because each file should be standalone and compiled as a smaller PDF. But then, I want to take all of the files we have and put them in a main document. I've looked at the other questions:

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}

\linespread{1.3}

\hypersetup{backref,  
    pdfpagemode=FullScreen,  
    colorlinks=true}

\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}
  • 2
    The combine package may help. See tex.stackexchange.com/questions/119415/…. You could also consider a master document with include and includeonly. – Ethan Bolker Jun 19 '13 at 17:43
  • Doesn't that still require that I build up my preamble manually? – user1532974 Jun 19 '13 at 17:48
  • Both the methods I suggested above allow you to create a preamble once and use it in several contexts. – Ethan Bolker Jun 19 '13 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. – user1532974 Jun 19 '13 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. – Ethan Bolker Jun 19 '13 at 18:18
4

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
1

The subfiles package does exactly what you are looking for. There are is a great documentation on ShareLatex 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}

Make sure to have subfiles.sty in your path. Also cross-references between the files are supported.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.