I have been trying to compile several LaTeX files and have been using \input to do this. However this causes some annoyances that I'm unaware of to fix (I'm using TexMaker as the editor)

  1. I get a lot of errors, if I include the preamble in any other file than the the main tex file that has \input-commands in it. As a result whenever I compile, I have to compile the whole document all the time.
  2. When you are using one file, TexMaker has this nice property where if you compile and then view your pdf using the GUI, then the pdf jumps to the point you have just been working on. This goes away when you use the \include command where the pdf just opens to the very last page.
  3. I sometimes accidentally hit compile with the subfiles in focus which throws all sorts of errors as the subfile doesn't have any preamble at all (not even a \documentclass).
  4. The helpful popups for \ref to add references are no longer present when you are working on parts of the file which complicates matters.

Short of putting everything back in to one unwieldy tex file, are there fixes for any or all of these issues?

For example, is there a package I could use that solves most of the issues? It would be great if 2), 3) and 4) have at least partial solutions. With 1) I can live with.

  • You can't use a preamble in an \input file with pure 'typesetting content'
    – user31729
    Jan 8, 2017 at 16:10
  • 4
    2, 3, and 4 are TexMaker problems. I use TeXStudio and all of those work nicely out-of-the-box. You can check out different editors and their features in this list.
    – hbaderts
    Jan 8, 2017 at 16:15
  • 1
    For point 3, you can define a master file via the Options menu. For pont 2, did you try with SumatraPDF as pdfviewer? For point 1, you can use \include in the place of \input, and \includeonly to compile only selected subfiles.
    – Bernard
    Jan 8, 2017 at 16:16
  • 1
    I'd expect any tex editor to be able to allow you to specify a master document so that you can work in an input file and it still finds the main document. I don't know texmaker but emacs has had that feature since the 1980s. Jan 8, 2017 at 17:01
  • 1
    @Dr.ManuelKuehner I assumed it did:-) Jan 8, 2017 at 17:59

3 Answers 3


1) I get a lot of errors if I include the preamble in any other file than the the main tex file that has \input commands in it. As a result whenever I compile, I have to compile the whole document all the time.

The way to go around this is the {subfiles} package:

Put\usepackage{subfiles} in the preamble of the main.tex.

other *.tex files are included by:

\subfile{sectionOrCapter} % no extention needed

Alls other *.tex files look like this:


 %% special definitions or command overrides here

% any LaTeX content

% any LaTeX content

% any LaTeX content


There are some points to keep in mind:

  • All subfiles refer to main.tex in their \documentclass command, even it they as "transitive".

  • the reference to main.tex is a *relative path, this means if your subfile is buried in a deep folder structure you have to add enough ../

  • if your subfiles are in file system folders you should use the \graphicspath command to point to the folder containing your images:





Alternatively you could swich to TexStudio as the successor of TexMaker wich can handle separately compile nested files on its own...

  • 1
    Just a minor detail, as far as I know, TeXstudio is a fork (kind of a Independent variant since 2009) and not not the successor of Texmaker (en.wikipedia.org/wiki/TeXstudio) Jan 8, 2017 at 17:53
  • @Dr.ManuelKuehner technically that's correct, but it feels that much better to work with it that I personally treat it as the "successor"... Jan 8, 2017 at 17:59
  • 1
    A software fork may very well be much better than the software package it descended from. That doesn't make it the successor, though.
    – Mico
    Jan 8, 2017 at 20:53
  1. If you have a a lot of packages used in your preamble, you should think of putting them in a mythings.sty package instead. The you can call \usepackage{mythings}. More infos there.

  2. It's complicated and I think that this is more of a Texmaker issue than a real LaTeX one.

  3. You just can't compile a file with no preamble so my answer is quite stupid, just don't try. If you do it, TexMaker has a "cleaning" function which will help you get rid of the various files produced by your compilation.

  4. The Ref popups don't work but it's just like for 2. Texmaker parse the entire document to help you but the file structure is descendant only (meaning LaTeX will parse from the main.tex document to the inputed ones and will not do it in reverse.). So if you Ref is not in the current file, it is strictly normal that Texmaker behave this way (I know it is annoying but as far as my knowledge go every text editor has the same problem, for example the \cite{} autocompletion don't work in included files in SublimeText, because the .bib the software doesn't know where to find the information.)


One option is the standalone package. In your main document, \usepackage{standalone}. In your subfile, \documentclass{standalone} and use your regular preamble. When you input/include a subfile, the standalone package will ignore everything until \begin{document} and then compile the rest of the file as normal. This lets you compile the main document like you've been doing already. On the other hand, you can now compile the subfile and not have the multitude of errors.

For my current large document, I don’t use the standalone package. Instead, I have a standalone.tex file that has the same preamble and then inputs the subfile I’m working on at the moment. This cuts the long compilation time down to all that is needed for the preamble and the file itself. The time for the file itself is unavoidable. The time for compiling the preamble can be cut by using a “precompiled preamble”, but I’ve not looked into those details.

Your Answer

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