0

I'm using SageMathCloud's LaTeX.

So I've got five .tex documents (all pretty long) with similar formatting. I want to add all five files into one large file that will respect the preambles of all five files.

I thought \include would be my best option. However, it is not working. By that I mean that I enter it and nothing happens, not even an Error. I've tried using \input, but this option does not respect preambles of the documents. Additionally, for some reason, the \input command won't work unless I use the standalone package.

I've been entering this:

\documentclass[12pt]{article}

\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{caption}
\usepackage{float}
\usepackage{pdfpages}
\pagestyle{fancy}

\begin{document}
\begin{titlepage}
\includepdf{cover.pdf}
\end{titlepage}

\tableofcontents

\include{doc1.tex}
\include{doc2.tex}
\include{doc3.tex}
\include{doc4.tex}
\include{doc5.tex}  
\end{document}
4
  • 2
    your question is very hard to understand, what do you mean by " not respect preambles of the documents" ? whether you use \input or \include the format of the files being included is the same and must not have a preamble of its own but be tex code that would be allowed at that point in the main document. May 29, 2016 at 21:47
  • @Nasser I think you're right and I might be confused. Is there any way to combine all the five documents together under one main document and have the preambles (and by that I really mean the formatting and such things) remain intact for all five documents? That is just simply import the files as is under one large file. Perhaps only having things like the page number change.
    – Alondra
    May 29, 2016 at 23:21
  • This was nicely detailed article. But I'm getting an undefinted control sequence for \subimport
    – Alondra
    May 30, 2016 at 2:03
  • @Alondra I don't think there is a general way to combine different documents with different preambles into a single file (other than compiling each one and then including them as pdfs for example). My answer below uses the same preamble (defined in master.tex for each document allowing you to treat them as independent documents, or as a combined document.)
    – mforbes
    May 30, 2016 at 20:17

1 Answer 1

1

The recommended approach for multiple files with Sage MathCloud (SMC) is to use the subfiles package. This allows you to use the same preamble for all files, but unlike \include or \input allows each subfile to be build on its own so you can edit them in a sensible manner online.

A complete working example can be found here.

Your master file, which I call master.tex here, should look like this:

\documentclass{article}

\usepackage{subfiles}   % This is the recommended solution for multiple files on SMC

\title{Title of Document}
\author{Name of Author}

\begin{document}
\maketitle
\subfile{doc1.tex}
\end{document}
%sagemathcloud={"latex_command":"latexmk -g -pdf master"}

(The comment at the end instructs Sage MathCloud how to build the master file - I am using latexmk here.)

Now your subfiles doc1.tex etc. should look like this:

\documentclass[master.tex]{subfiles}
\begin{document}
\section{File doc1}
\end{document}
%sagemathcloud={"latex_command":"latexmk -g -pdf doc1"}

When you edit this file on SMC, you should only get the file doc1.tex but typeset with the full preamble (so you can quickly edit only that section without recompiling everything for example).

2
  • I keep getting an issue warning that \documentclass[master.tex]{subfiles} is causing an emergency stop. The subfiles either have a LaTex Error: missing \begin{document} or Missing Number,treated as zero
    – Alondra
    May 30, 2016 at 13:50
  • @Alondra If you save the two examples given above as master.tex and doc1.tex, then you should be able to compile the files on SMC (I just tried it). If something does not work, you will have to post a more specific (not)working example.
    – mforbes
    May 30, 2016 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .