# Faster way to compile a document [duplicate]

Writing a long document, compilation with Texmaker becomes too slow, so when I want to see how it looks, I loose time (not too much, but it is getting worse because of document's size).

Is there any way to compile faster?

• I guess it really depends on what "making some changes" entails. Please be more specific. – Mico Jun 5 '17 at 10:57
• Which editor do you use? TeXStudio f.i. has a kind of preview feature. – TeXnician Jun 5 '17 at 11:01
• Have you tried providing the document class option draft? It should speed up compilation dramatically (at the loss of not getting graphs included inside figure environments and not getting hyperlinks formed. Math material will still be compiled, though. Depending on what you need to achieve, setting the draft option may be worth it. – Mico Jun 5 '17 at 11:55
• You can set a main file containing the preamble,\include{file-nn.tex} directives in the body of the document, and an \includeonly{list of files to be compiled} directive in the preamble. – Bernard Jun 5 '17 at 12:11
• You do not give precise details what takes time. In case you have complicated tikz images it might be a good idea to "externalize" (you can read about that in the tikz documentation as well as on this site). But I think your question would be better if you found out what takes time. The solution will be different depending on that. – mickep Jun 5 '17 at 12:34

In a similar situation I decided, that when writing on a text passage I seldom need to see the whole document, but that compiling the current chapter/section/whatever is enough. For this task I use the subfiles package. With this package I can both compile the main file to get the complete output and the individual chapters alone to save time. Compiling the individual will still have the packages from the main file available and the look and feel of the document will be the same.

My file look like this:

main.tex:

\documentclass{book}
\usepackage{subfiles}

\usepackage{xcolor}% Just an example for all packages you want to use

\begin{document}
text

\subfile{chapter1}
\end{document}


and chapter1.tex

% !TeX root = chapter1.tex   % not necessary, but some editors think they are smart
\documentclass[main]{subfiles}

\begin{document}
the content of chapter 1, \textcolor{blue}{using packages from the main file}
\end{document}


Most of the time I use this together with

\usepackage{xr-hyper}% or \usepackage{xr} if you don't use hyperref
\externaldocument{Chapter2}


which can be used to access labels etc. from for example other subfiles

or with

\usepackage{zref-xr}
\zxrsetup{toltxlabel}
\zexternaldocument*[main-]{main}


to access things like pagenumbers or chapter numbers from the main file.

• Do subfiles have to be in same folder as main.tex? Your answer works only if i put my chapters in same file that main.tex is.. – santimirandarp Jun 12 '17 at 17:39
• @santimirandarp It's 100 times easier if you just have all the files in one folder. If you insist on subfolder, you probably have to adjust the path both in \documentclass[../main]{subfiles} and \subfile{./foldername/chapter1} [untested] – user36296 Jun 12 '17 at 19:00

I highly recommend recompiling often. Here are some thoughts which were too long for a comment:

1. You can see whether your code corresponds to what you wanted to achieve.
2. You get compiler errors quite early and thus you can detect and resolve them more early and easily. When I code some more complex math formulas, I even compile while writing the formulas to check whether what I wrote this far is correct.
3. Some people (not me) like WYSIWYG editors like Lyx (LaTeX Editors/IDEs), so you might want to try or read about it. And some people use Lyx and apply some fine-tuning with another editor afterwards.

You might want to compare What are good learning resources for a LaTeX beginner?.

In the end you can choose your workflow freely, so just see this as my opinion. The problem is of course the runtime. You cannot always get what you want. These might "speed up" the runtime:

1. Upgrade your engines (this helped me a couple of times). New distributions have just arrived.
2. If you have a small document, compile time usually is not an issue. If you have a larger document like a book, consider to divide your project with \input or \include and comment the temporarily uninteresting sections/chapters out or use \includeonly or the subfile-package (as mentioned by TeXnician and samcarter).
3. Get a faster computer. Not an easy one.
4. As others has have pointed out: Use draft modes.
5. If you use Tikz and plots, you might want to generate the plots using gnuplot.
6. Tikz is not build to be fast. Tikz-pictures can be externalized as pointed out by mickep correctly. You also might also consider inkscape as an alternative.
7. The use of saveboxes might be appropriate.
8. I am not sure whether a different engine like LuaTeX might speed up the compile time. This also might depend on your use of the Lua language, e.g. I once gained several minutes by writing a script in Lua instead of using \foreach directly.
9. Compiling a document on a terminal and not in a IDE might be faster.
10. See Speeding up LaTeX compilation.
• Please be aware that an engine upgrade might also slow down. And engines like Xe/LuaLaTeX are always slower than pdflatex. – TeXnician Jun 5 '17 at 11:15