Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
@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
add comment

2 Answers 2

up vote 3 down vote accepted

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);
    \newcommand*{\XRadius}{4.0}
    \newcommand*{\YRadius}{3.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
        (EllipseOrigin) ellipse [x radius=\XRadius,y radius=\YRadius];

    \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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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