I am using \write18 enabled (or --shell-escape) with externalization to compile a bunch of PGFplots. The first run takes much time, and I noticed that pdflatex only runs on one CPU core. Is there any way to have pdflatex use multiple cores? (at least when \write18 is enabled)

  • 12
    Since you explicitly mentioned the use of external: you can configure the external library to run in mode=list and make. The resulting makefile can be processed in parallel using make -j 8 -f <file>.makefile (in this case on 8 threads). Only feasible if you can resort to make, though... Commented Oct 6, 2013 at 14:12
  • 3
    Note that the keyword "external library" means that this question is no duplicate. Commented Oct 6, 2013 at 14:13
  • What OS are you using? At least on UNIX-like systems it may be enough to end the command line passed to \write18 with an ampersand character (&) to have the shell spawn a new process for the external command.
    – Daniel
    Commented Nov 21, 2013 at 13:20
  • 1
    Could you give a minimal working example (MWE) that illustrates your problem, in particular, allows us to experiment with your method of "compiling a bunch of PGFplots"? Commented Nov 26, 2013 at 13:45
  • 1
    @StephanLehmke your feature request with asynchronous processing sounds interesting; but I fear that it would easily run out-of-control unless you restrict the number of background processes. And that, in turn, sounds like a very complicated method in TeX ... compiling twice would be simple. If you want to experiment with the code; feel free to do so. Commented Dec 25, 2013 at 14:30

1 Answer 1


The externalize in tikz may generated individual picture for every \begin{tikzpicture}...\end{tikzpicture}.

  • \usepgfplotslibrary{external} let all pgf-plots outside of the compile.

Let pdflatex know those pictures are compiled with make.

  • \tikzexternalize[mode=list and make] let tikz to know we would use the make. Because at present only the make support multi-thread.

I'm lazy to set the name for every pgfplots figure, so I let it done by system.

  • external/system call set names for individual picture file, or the pdflatex doesn't know what file name should be set. (Origin code is from package tikz&pgf Manual for Version 2.10 page 345.)

My tex file is named test.tex


    \usepackage{pgfplots} %use tikz based pgfplots
        \tikzexternalize[mode=list and make]
        \tikzset{external/system call={pdflatex \tikzexternalcheckshellescape
          -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}
        } % to let pdflatex work
    %% compile picture: pdflatex --shell-escape xxxxxxx.tex


    \begin{axis}[ xlabel=$x$, ylabel={$f(x) = x^2 - x +4$} ] 
      \addplot {x^2 - x +4}; 

      \addplot[color=red,mark=x] coordinates 
      { (10,100) (20,150) (40,225) (80,340) (160,510) (320,765) (640,1150) };


After first pdflatex compiling, do the make -j 4 -f test.makefile. 4 compiles the pictures with 4 thread.

Then run pdflatex second time.

The option --shell-escape also work fine in my system.

My system is:

  1. Win 7(x64) + Miktex 2.9 + make under cygwin environment
  2. Linux(x64) + Texlive2013 + make
  • 1
    Interesting, but could you elaborate what you are doing here? What is the sense of tikzexternalize ?
    – Keks Dose
    Commented Dec 25, 2013 at 11:38
  • I try explain the option I used, But it looks a bit weird in style.
    – Tawei
    Commented Dec 26, 2013 at 6:15
  • This approach does not seem to work when the tikzpictures are imported with an \input{file.tikz} command. But maybe it's just a matter of properly naming the imported files.
    – tigerjack
    Commented Mar 13, 2019 at 18:15
  • Reviewing chapter 53 of the pgfplots manual may clarify some of the techniques @selwyndd21 is using here.
    – ZaydH
    Commented Jan 10, 2020 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .