13

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?

  • 2
    I guess it really depends on what "making some changes" entails. Please be more specific. – Mico Jun 05 '17 at 10:57
  • 2
    Which editor do you use? TeXStudio f.i. has a kind of preview feature. – TeXnician Jun 05 '17 at 11:01
  • 4
    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 05 '17 at 11:55
  • 5
    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 05 '17 at 12:11
  • 4
    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 05 '17 at 12:34
  • 2
    @santimirandarp The subfiles package is very handy to compile individual chapters without compiling the whole document. But if you just want to know how a single equation or similar looks like, some editors have a preview function - for example texstudio has one and is very similar to the editor you use. – samcarter_is_at_topanswers.xyz Jun 05 '17 at 14:53
  • 2
    @santimirandarp I'm (99.99999%) sure your files will still work if you use texstudio instead of texmaker, as they are both just editors, all the typesetting etc is done by your tex distribution. You can always have both editors installed at the same time - so if for whatever reason you don't like texstudio, you can simply switch back to texmaker and no harm is done. – samcarter_is_at_topanswers.xyz Jun 05 '17 at 19:10
  • TeX was designed to produce something that will be left untouch, so it is not optimized for fast compilation. I use LuaLaTeX to compile the documents (cool Lua features and fonts supprort), which makes the document compile 2-3 times longer, than with pdfTeX. But to get a good look, you have to wait. – Michael Fraiman Jun 05 '17 at 20:47
  • The duplicate does not relate to the number of images. – Schweinebacke Jun 06 '17 at 09:08
  • I've read it! Please do not insinuate the opposite. This wouldn't help anybody. The question and most of the answers, e.g., using -draftmode or \include and \includeonly are independent from images. – Schweinebacke Jun 06 '17 at 10:26

2 Answers2

11

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 naturally is 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 and Is it possible to use GPU acceleration on compiling large LaTeX documents?.
CampanIgnis
  • 4,624
  • 1
    Please be aware that an engine upgrade might also slow down. And engines like Xe/LuaLaTeX are always slower than pdflatex. – TeXnician Jun 05 '17 at 11:15
10

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.. –  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] – samcarter_is_at_topanswers.xyz Jun 12 '17 at 19:00