# Compiling multiple tex files into a single file

I was writing my masters' thesis using Latex and have written 4 chapters in 4 different .tex files. Now I wish to combine all these chapters into a single .pdf file. For this I wrote a main .tex file in which I included the 4 tex files using \include statement. However, everytime I run the main tex file, I see an error message :

Message : ! Latex error ! Can be used only in preamble.

What I wrote in the main tex file was the following :

\documentclass[10pt]{thesis}
%\usepackage{pgf}
\usepackage{varioref}                                                               %   when using \vref the page the figure is on is printed
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{subfigure}
\usepackage{array}
\usepackage{url}                                                                    %   makes nice url's
\usepackage[a4paper, left=3cm,right=3cm,top=4cm,bottom=4cm]{geometry}
%\usepackage{mathcomp}
%\usepackage{mathptmx}
\usepackage{graphicx,color}
\usepackage[english]{babel}
\usepackage{bbm}                                                                    %   enables \mathbbm
\usepackage{lscape}                                                                 %   enables landscape tables
%\usepackage{lettrine}                                                               %   enables dropcaps ('miniaturen')
\usepackage{float}
\usepackage{caption}

%\usepackage{here}
%\usepackage{rotate}
%\usepackage{fancyhdr}
\usepackage{multirow}
\usepackage{picins}
\usepackage{a4}
\usepackage{braket}
\usepackage{cite}

\begin{document}
\include{Chapter1_Introduction_Final}       % Names of my tex files
\include{Chapter2_STIOS}
\include{Chapter3_FrequencyStabilization}
\include{Chapter4_VHDLperformance}
\end{document}


If I compile each .tex file individually , then I get separate .pdf files. However, I want to generate a single .pdf file consisting of all 4 chapters. I would be obliged for the assistance.

• There are packages that try to automate including separate documents but the simplest thing to do is do as you have done and use the standard \include and then remove the preamble and document environment of each of the chapters. – David Carlisle May 29 '14 at 11:00
• Exactly the same as @DavidCarlisle: Make sure your chapters only start by \chapter{Chaptertitle} and only include the text itself. At this point of inclusion they should not be standalone, i.e., they should only require your preamble of your main file – Mario S. E. May 29 '14 at 11:02
• – barbara beeton May 29 '14 at 12:48
• For one possible strategy see my answer to tex.stackexchange.com/questions/123058/… – Ethan Bolker May 29 '14 at 13:03

It appears that you have a separate preamble in each of your sub files. Latex can only handle one preamble in the master document. You could now either delete/comment the preamble in the chapter-files, or you can use the combination of the standalone package-class combination.
In your chapter files you can use the documentclass \documentclass{standalone} and in your master file you load the \usepackage{standalone}.
To keep your source clean, I would recommend to only have the preamble in the master document, but compile a part of your document by means of \includeonly{} or \excludeonly{}. For \excludeonly, you need to load the underlying package by \usepackage{excludeonly}. The advantage of this approach is that the chapter and page numbers will be like in the complete document, whereas compiling single chapters fully standalone will result in multiple chapters 1.