[texhax] General Advice on Combining Documents for a Thesis

Susan Dittmar Susan.Dittmar at gmx.de
Mon May 31 11:42:25 CEST 2010

It is possible to combine several stand-alone-documents into a bigger
document without removing the \begin{document} and \end{document} lines or
the preamble. I do this quite often. What you need for that is to make sure
that all definitions of the document preamble of the embedded documents are
also in the surrounding document (perhaps using a separate file for those

There exist several ways you can accomplish this. I use the following

Start every document with:

% check whether this is a stand-alone or embedded document:
% only read preamble if this is a stand-alone document:

Then follows \documentclass{...} and the whole preamble. It will only be
read in the stand-alone document, not in case of embedding it.

This part ends with


followed possibly by a title page and the rest of the front-matter that
should not be included in the embedded version. The true end of this block

\fi	%\ifstandalone

Everything that follows now will be used for both versions. Wherever you
want to differentiate between the stand-alone and the embedded version, you
can enclose it in

	% this will only be in the stand-alone version
	% this will only be in the embedded version
\fi	%\ifstandalone

The document then will end with another of those \ifstandalone blocks, but
a special one.

    %here comes all the back-matter stuff that should not be included in the
	%embedded version

	% ...

\else	%\ifstandalone
\fi		%\ifstandaline

The construct in the \else block makes sure that the \end{document} line
(which *must* be outside of the \ifstandalone\else\fi construct!) is not
reached in case of embedding this file.

The file itself can be embedded with the \input and the \include
commands, as you desire.

In case you want to keep the different documents in different directories,
I recommend using the fink package. It helps keeping track of the current
filename and directory and thus allows relative file paths (relative to the
current file, not to the main document).

Hope that helps,


More information about the texhax mailing list