Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I wonder how I can speed up the pdflatex compilation of a large document (thesis) with >200 pages and many images (however all imported PDFs or imported pixel graphics, no TikZor similar things yet!). My current LaTeX project has several source files, combined with \include.

I read about latexdaemon which seems to be able to precompile the preamble to save time.

  • Is there anything similar I can use on MacOS X?
  • Are there ways to only process the things that have really changed? (I'm currently editing many chapters at the same time, so \includeonly seems not helpful.)

I use TexMakerX as editor and Skimas viewer.
I've configured latexmk to automatically do several pdflatex runs (see Automatically start the necessary pdflatex runs if .tex has changed (MacOS X)?).

Skim does autoupdate the PDF file, as soon as it has changed.

share|improve this question
add comment

3 Answers 3

up vote 14 down vote accepted

Take a look this description. It's a description of how to format the preamble yourself. Assuming your source file is main.tex, it all comes down to these steps (which were copied from the link and modified by mefor my own use):

  1. Rearrange your preamble so that its static part precedes any dynamic part. What in the preamble can be “dynamic”? For example, if you use \includeonly, you probably want to change its argument rather frequently and so it is not static. Finally, some packages read and write auxiliary files when you issue a command that you should put in the preamble (eg, nomencl uses `\makenomenclature). Clearly, you have to run these commands in every run.
  2. Extract the static part of the preamble into, say, preamble.tex. At this point, main.tex no longer contains the static part. It should start with the dynamic part, or simply `\begin{document} if you have nothing dynamic.
  3. Execute:

    pdflatex -ini -jobname="preamble" "&latex preamble.tex\dump"
    

    in the command line. You will notice that a new file `preamble.fmt has been generated in the same directory, along with other auxiliary files.

  4. Edit the first line of main.tex so that it starts with %&preamble.

  5. Execute latex main.tex as usual:

    pdflatex -shell-escape main.tex
    

    You may get an error about the class file immediately, or you may notice that latex finishes as usual. But if you have paid attention to the output, or if you inspect the the log file, then you will see that the preamble gets processed in “no time” at all. At this point, cheers!

To make things slightly fancier, here is an modification. First, add this to the end of preamble.tex:

\def\preambleloaded{Precompiled preamble loaded.}

Then, before the dynamic preamble (or \begin{document} if there is none) of `main.tex, add:

\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax} \ifundefined{preambleloaded}
\typeout{PRECOMILED PREAMBLE NOT LOADED}\input{preamble} \else
\typeout{\preambleloaded}
\fi

The idea is to define a macro in the precompiled preamble and use it to detect if the precompiled preamble has been loaded or not. If not, \input{preamble} will be used to pull the static preamble back in and you will not see any error at all.


Also, if you are using tikz to make figures, have a look at the external library. Check the Tikz and Pgf manual, section 32 describes how to use it.

share|improve this answer
1  
That is a nice link, but we prefer answers which are mostly self contained. Links can break. It would be great if you would outline the solution in you answer. Also please do not create "here" links (see Can we have some linking etiquette and guidelines?). –  Martin Scharrer Apr 12 '11 at 13:42
5  
ok, I've edited my post. –  romeovs Apr 12 '11 at 18:01
    
+1 thanks a lot. Nice answer. –  Martin Scharrer Apr 12 '11 at 18:26
1  
@Martin I don't know if you can add up the compilation time of preamble and main to get the standard compilation time. Als, I don't use latexmk and therefore do not know what it does exactly, my guess is that it only compiles preamble.tex once. You could check this by constructing a very bulky preamble and running that several times, looking for speed changes. As for dynamic commands, I just meant the commands that you might alter a lot when working in main.tex (eg. a macro that might change). Macro's that edit auxiliary files should also be considered dynamic (as mentioned above). –  romeovs Jun 12 '11 at 15:15
2  
@romeovs: Thanks for this nice answer! It’s a nice feature but I had to replace "&latex preamble.tex\dump" width "&pdflatex preamble.tex\dump" because I have JPG-images. May you’d like to add a nota abut this to your answer. –  Tobi Jan 11 '12 at 16:09
show 5 more comments

for all except the last pdflatex run use -draftmode

pdflatex -draftmode file

taken from the documentation:

   -draftmode
          Sets \pdfdraftmode so pdfTeX doesn't write  a  PDF  and  doesn't
          read any included images, thus speeding up execution.
share|improve this answer
    
I already use the option draft in the fixme-Package, is that the same? -- and. with "last run" do you mean the last run of those in latexmk each time, or only "the one" very last run to produce the final document? –  Martin Apr 12 '11 at 10:50
    
I am talking about an option for pdflatex and not of a package option. The last run is the last pdflatex run. –  Herbert Apr 12 '11 at 11:09
1  
@Herbert: Thanks! I just knew about the package options and wondered if they just might activate the corresponding option for pdflatex. For the "last run": I hope I did not misunderstand you, so how can I tell latexmk to use -draftmode for all runs except the last one? –  Martin Apr 12 '11 at 11:54
1  
pdflatex is already running when reading the package options and -draftmode is far different to a draft option. Look into the latexmk or write to the author, that he should take the option into account. –  Herbert Apr 12 '11 at 12:07
1  
see also: tex.stackexchange.com/questions/8317/… –  Herbert Apr 12 '11 at 12:28
show 2 more comments

Setting in the preamble

\pdfcompresslevel=0
\pdfobjcompresslevel=0

reduced the compile time for my (current version of my) thesis from 2:05 to 1:01 (Minutes:Seconds), but also increased the size of the pdf from about 65 MB to 718 MB (seven hundred eighteen Megabyte). Therefore for the final pdflatex run probably

\pdfminorversion=4% or 5 or 6...
\pdfcompresslevel=9% which is really slooow
\pdfobjcompresslevel=3% maybe reduce to 2; 3 might not be supported by all readers

should be used. If you use a version control system making (uncompressed) backups also of the pdf, you should think about what to do with the 718 MB files...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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