# Including full-fledged files in a single document [duplicate]

Possible Duplicate:
Make a .tex file that combines complete .tex documents in subdirectories

I have a couple of files, which were initially intended as stand-alone documents. But now I wish to compile them in a single document. The problem is that each of them has its own specific packages, titles, etc and the \include method isn't so straight forward for such documents. (I have to include the same list of packages in the main file, and comment them all out in the sub-document, which is a long manual procedure.)

What is the best method to compile them all in one, besides externally merging PDFs?

-

## marked as duplicate by lockstep, Werner, Seamus, egreg, Joseph Wright♦Dec 4 '11 at 14:17

@lockstep: It sounds more to me that the OP has small documents, while the standalone package is more for smaller things like picture environments. This looks more like a case for using the combine class. – Martin Scharrer Dec 4 '11 at 13:00

I have been using the {standalone} package exactly for this purpose. The main files should use:

\documentclass[preview=false]{standalone}


or load the standalone package near the beginning of the preamble. The complete preamble needed by the sub files should be loaded by the main document.

In the example below, I have used the filecontents package just to be able to wrap the sub file into one code sample. So, the file subfile.tex here is a sub file, in this case it is composed of a tikz figure. This file can be compiled on its own. The main file is loading:

\usepackage{standalone}
\usepackage{tikz}


and then simply uses \input{subfile} to import the sub file.

## Code:

\documentclass{article}
\usepackage{standalone}
\usepackage{tikz}

\usepackage{filecontents}
\begin{filecontents}{subfile.tex}
\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\coordinate (EllipseOrigin) at (0,0);

\draw [blue, thin, ->] (-5,0) -- (5,0) node [right] {$x$};
\draw [blue, thin, ->] (0,-4) -- (0,4) node [above] {$y$};

\draw [red, ultra thick]% Graph Ellipse

\end{tikzpicture}
\end{document}
\end{filecontents}

\begin{document}
\input{subfile}
\end{document}


There is also the subpreambles package option to the standalone class which allows you to use the preamble form the sub files. So if you can not have one preamble in the main file for all your subfiles, perhaps this might be a useful option.

There is also the combine package, which also lets you combine separate documents into one document.

-

In addition to the linked question, the subfiles package provides a similar functionality. From the package README:

Using subfiles the user can handle multi-file projects more comfortably making it possible to both process the subsidiary files by themselves and to process the main file that includes them, without making any changes to either.

-