# How can you smoothly merge two .tex files into one without changing document style, etc

Here is a description of my problem:

I have two documents, a main text and a supplementary text (both written in tex), which I would like to combine and submit to arXiv. arXiv requires that I submit a single .tex file. I attempted to submit a single file that combined two pdfs using pdfpages. My submission was eventually put on hold and they contacted me to say that using pdfpages was against the rules (this wasn't clear to me when I submitted it. In fact, I saw another SE post suggesting someone use this exact method to submit to arXiv).

How can I combine these two tex files into one? Is there some command that can reset all parameters within a tex file? My hope is that there is some command like the following (with \BEGINNEWDOC acting like I suggested):

% document 1 (main text)
\documentclass{article}
\title{title 1}
\begin{document}

\maketitle

\section{Introduction}

text...

\end{document}

\BEGINNEWDOC

% document 2 (supplementary text)
\documentclass{article}
\title{title 2}
\begin{document}

\maketitle

\section{Introduction}

text...

\end{document}



Then this single file would be like creating the two documents separately then manually combining the pdfs.

I am using Overleaf to edit the documents if that is relevant.

• Does this answer your question? When should I use \input vs. \include? – sRaviolii Mar 16 at 21:58
• If you have two .tex files with the same preamble, you can just copy the contents between \begin{document} and \end{document} from the second file into the first one, can't you? I don't fully understand the problem here. Using \include or \input you will still need to submit the other files to be included. If you are not allowed to submit more than one file, I fear, there is no other way than to do some handiwork. But perhaps, I did not understand your case correctly. – Jasper Habicht Mar 17 at 12:08
• @JasperHabicht No, because they each have their own titles, author lists, styles, etc. – dylnan Mar 18 at 15:14

I think, what you may be looking for is the subfiles package. Your problem could be solved as follows:

\documentclass{article}

\usepackage{subfiles}
\usepackage{titling}  % if you need separate title pages for the subfiles

\begin{filecontents}{myfirstfile.tex}
% document 1 (main text)
\documentclass[main]{subfiles} % !
\title{title 1}
\begin{document}

\maketitle

\section{Introduction}

text...

\end{document}
\end{filecontents}

\begin{filecontents}{mysecondfile.tex}
% document 2 (supplementary text)
\documentclass[main]{subfiles} % !
\title{title 2}
\begin{document}

\maketitle

\section{Introduction}

text...

\end{document}
\end{filecontents}

% The actual document that combines both of the above documents ignoring their preambles:

\begin{document}

\subfile{myfirstfile}

\subfile{mysecondfile}

\end{document}


With this code, the files you want to include are generated when you compile the document and than included into the main file by ignoring their preambles. Note that you need to change the document class of the subfiles.

You could, of course, also just include the supplementary text into your main file (the one that contains the main text) as a subfile, which might be a bit simpler.

If you want to have multiple title pages in your final document, you can make use of the titling package.

The combine class is meant for this. Assuming that your two files are document1.tex and document2.tex then the following should typeset them as a single output.

    % combineprob.tex SE 587632
\documentclass[11pt]{combine}

\title{TITLE}
\author{AUTHORS}

\begin{document}

\maketitle

\begin{papers}
\import{document1}

\import{document2}

\end{papers}
\end{document}


However, there is a temporary problem in that the combine class needs updating and I have suggested to the maintainer what should be done.