5

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.

dylnan
  • 161
  • 1
  • 3
    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 '21 at 12:08
  • 2
    @JasperHabicht No, because they each have their own titles, author lists, styles, etc. – dylnan Mar 18 '21 at 15:14

2 Answers2

5

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} % ! \begin{document} \title{title 1}

\maketitle

\section{Introduction}

text...

\end{document} \end{filecontents}

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

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

enter image description here

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.

  • Running this led me to an error: ./myfirstfile.tex:10: LaTeX Error: No \title given. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.10 \maketitle – Gabe Conant Sep 05 '23 at 17:56
  • @GabeConant Hm, you're right. Well, it is probably better to move the \title command after \begin{document} then. It seems that the problem is that the preamble is removed from the subfiles and thus the \title command is also removed which causes the error. – Jasper Habicht Sep 05 '23 at 18:17
3

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.

Peter Wilson
  • 28,066