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)
- 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. - 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. - 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
). - 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.
Best Answer
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:
Alls other *.tex files look like this:
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:main.tex
subfolder/someSubfile.tex
Alternatively you could swich to TexStudio as the successor of TexMaker wich can handle separately compile nested files on its own...