From your question it seems that file
and file
are complete standalone files that are intended to be able to be compiled individually. If that is the case then you should consider the standalone
package. This needs to be loaded in the bigfile
early in the premable, and bigfile
needs to include all the packages required by both files.
Here is how I would recommend that you do this:
mypackages.sty
:
While this is not absolutely necessary, I would recommend that you create a mypackages.sty
file which has all the packages required by your completed document:
\usepackage{standalone}% Need standalone package
\usepackage{amsmath}% any others that you use
This file should be your master and include all your customization such as page geometry, margins, etc...
This will simplify maintaining the preambles, and ensure that the files compiled individually are formatted identically when included in the main document.
file1.tex
and file2.tex:
Each of the individual files should look like:
\documentclass{article}
% Preamble of file <n>
\usepackage{mypackages}
\begin{document}
... File n contents here ...
\end{document}
Note that these are complete files and can be compiled by themselves.
bigfile.tex
:
\documentclass{article}
\usepackage{mypackages}
\begin{document}
\input{file1}
\input{file2}
\end{document}
Notes:
Here is the complete code in one file. Here I have used the filecontents
package to be able to include the individual files to produce a compilable example. Below, I have not used a mypackages.sty
to show that only the main file needs to include the standalone
package.
\documentclass{article}
\usepackage{standalone}
% Complete premable required by all files...
\usepackage{amsmath}
%-----------------------
\usepackage{filecontents}
\begin{filecontents*}{file1.tex}
\documentclass{article}
% Preamble of file 1
\usepackage{amsmath}
\begin{document}
... File 1 contents here ...
\end{document}
\end{filecontents*}
\begin{filecontents*}{file2.tex}
\documentclass{article}
% Preamble of file 2
\usepackage{amsmath}
\begin{document}
... File 2 contents here ...
\end{document}
\end{filecontents*}
%----------------------
\begin{document}
\input{file1}
\input{file2}
\end{document}