What would be the most efficient way to compile a document of the article class with many TikZ subfiles?

In the main document, I have added \usepackage{standalone} and then \includestandalone for the individual subfiles.

  1. Would it be better to add the options subpreambles = true, sort = true, and trim all the TikZ preambles from the main document?

  2. Or should I not use those options and keep all the TikZ preambles in both the main .tex file and the subfiles?

Which method would speed up compiling? If neither of these methods are truly efficient, what should I do instead?

As it stands now, my document is around 60 pages but it takes a few minutes to compile. I have over 30 .eps figures and over 30 TikZ subfiles. Besides the TikZ code, everything else is pretty standard LaTeX.

The document class for the subfiles is standalone with the option convert = false.

One of the other problems that slows down compilation is the fact that every standalone picture is compiled when the main document is compiled. However, there may have been nothing change with 95% of the pictures.

Main example doc:

text here
text here

test example doc

\documentclass[convert = false, tikz]{standalone}
  \draw (0, 0) circle[radius = .35cm];
  • 3
    Take a look into tikz-external (tex.stackexchange.com/questions/tagged/tikz-external) at least for the TiKZ stuff that should be exactly what you are looking for
    – sheß
    Commented Jul 19, 2013 at 19:54
  • @sheß is there a specific thread you have in mind I should look at?
    – dustin
    Commented Jul 19, 2013 at 20:05
  • 2
    it's actually pretty streight forwards, except for a few minor problems you might encounter depending on what exactly you're doing. Basically, what you need to do is to load the library via \usepgfplotslibrary{external} and run pdflatex (or whatever you're using) with the option -shell-escape. A short introduction is given here: olezfdtd.wordpress.com/2012/03/28/…
    – sheß
    Commented Jul 19, 2013 at 20:19
  • Although tikz externalization works, I find it incredibly slow. Even if a figure already exists and it is not recompiled, the compilation time or the main document is drastically increased, compared to just including an pdf image created as a standalone tikzpicture.
    – Markus
    Commented Jul 19, 2013 at 21:07
  • 2
    @Markus This is very odd since tikz-external does exactly that: rendering the tikz picture into a PDF and including that.
    – Christian
    Commented Jul 20, 2013 at 2:36

1 Answer 1


I use the suggestion in zeroth's discussion. The discussion is for pdflatex.

However, I use xelatex, and I only test the methods by texlive on Linux x64 system.

here is my way to make it works for xelatex compiler:

  1. In the document preamble after \usepackage{tikz}:

      \tikzexternalize[figure list=false,prefix=tikz/]
        % make tikz externalize and store in directory "tikz"
      \tikzset{external/system call={xelatex \tikzexternalcheckshellescape 
        -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}} 
        % to let xelatex work

    and use the command xelatex -shell-escape xxxxxxx.tex to compile the picture externalized. (Till now the normal xelatex xxxxxxx.tex command would return errors)

  2. Once all independent pdf files compiled, normal xelatex xxxxxxx.tex should works as usual.

It's not perfect way to do tikz figure externalized because the options here cannot recognize whether the externalized pdf files are identical to new tikz figure.

  • I will check this out. It may take me a few days to test this though.
    – dustin
    Commented Aug 29, 2013 at 7:40
  • Maybe you could just tell what platform and compiler you use? That may help others to find the answer.
    – Tawei
    Commented Aug 29, 2013 at 8:43
  • Ubuntu 13.04, 64bit and I use Emacs with AUCTeX and Latexmk.
    – dustin
    Commented Aug 29, 2013 at 11:53

You must log in to answer this question.

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