It's my first post here; hopefully I'm not butchering how I'm supposed to post this. I'm working in the Report class using Arara, trying to use \input to import a chapter.

% arara: pdflatex % arara: bibtex % arara: pdflatex % arara: pdflatex
\documentclass[12pt, twoside]{report}

\chapter{Basic Notions}


I then receive this error. The path for the file is correct.

Chapter 1.

! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.

l.2 \documentclass
                  [12pt, twoside]{report}

Does anyone know what might be happening? Thanks a lot!

  • 3
    Welcome! You have \documentclass in ch1.tex. That won't work. Either load a package which will get rid of it or remove it. \input{} is just like putting the contents of the file there. So just as you can't have two \documentclass in one file, you can't have one in one file and one in a file you \input. – cfr May 27 '17 at 3:16
  • Off-topic: It is really not recommended to use the BibTeX backend with Biblatex now. Can you not use Biber instead? – cfr May 27 '17 at 3:17
  • You need to look into the combine or standalone class/package. – Werner May 27 '17 at 3:23
  • Yup, that worked! Thanks! I might mess with the bibliography stuff if it stops working again, but that's the only way I could get it to work. – John Samples May 27 '17 at 3:23
  • @Werner Do you want to write an answer? – TeXnician Jul 1 '17 at 11:08

You can definitely combine separate documents into a single one, but one of the main requirements for using \input (and \include) is that the sub-documents are void of any preamble-specific commands.

For example, if you have main.tex:

% main preamble stuff

your subfile.tex cannot include something like

% sub-file preamble stuff
\section{Some section}
Some text

One would consider subfile.tex to be completely "stand-alone" from main.tex in the sense that you can compile subfile.tex and receive an output document. In order to incorporate such a stand-alone file into another, you'll have to use special packages that ensures content within the sub-file preamble is ignored (including the use of the document environment). For this, packages like combine and standalone comes to mind. There are others as well, as discussed on the CTAN Topic of Subdocs.

Of course, if the construction of the files can be controlled, just remove all the preamble (and document environment) stuff from subfile.tex so it resembles only

\section{Some section}
Some text

Then using \include or \input would work as expected (and without problem).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.