As explained in the pgf manual under 32.4 and in various other questions/comments here on TeX.sX (https://tex.stackexchange.com/a/44508/9077, https://tex.stackexchange.com/a/32363/9077, https://tex.stackexchange.com/a/23565/9077), it's possible to export a TikZ picture as a pdf with document like this:

% main document, called main.tex
\tikzexternalize % activate!
\node {root}
child {node {left}}
child {node {right}
child {node {child}}
child {node {child}}

The problem, however, is that neither the manual nor these answers provide any detailed explanation for how to compile this document. I'm using texlive in Windows 7 with TeXworks, so please do not suggest command line compilation procedures.

I need to compile with XeLaTeX since I'm using fontspec. My XeLaTeX compilations look like the following:

enter image description here

enter image description here

What do I need to change to be able to use the external TikZ library?

  • You need --shell-escape active. – Qrrbrbirlbel Nov 10 '13 at 20:21
  • @Qrrbrbirlbel Yes, the manual and the questions I link to say something of that sort, but I have tried to add --shell-escape in various places, but it never works. Could you (or someone) please provide a complete compilation procedure for XeLaTeX? – Sverre Nov 11 '13 at 11:32
  • xelatex --shell-escape --synctex <filename> should do. However, you also need to setup external to use XeLaTeX, especially if the preamble uses XeLaTeX-specific stuff, the /tikz/external/system call needs to be setup correctly. – Qrrbrbirlbel Nov 11 '13 at 19:13
  • @Qrrbrbirlbel 1. The inclusion of <filename> there indicates to me that this is a command line interface? I don't use the command line, so I wondering (as indicated in my question) what I need to include in TeXworks compilation. 2. I'm sure I need to set up external correctly, but I have no idea how to do that ... – Sverre Nov 11 '13 at 19:46
  • 1
    @Sverre please see here: tex.stackexchange.com/questions/82699/… – Paul Gessler Mar 2 '14 at 14:23

With the help of Paul Gessler's link to How to enable shell-escape in TeXworks?, --shell-escape can be added to the XeLaTeX compilation in TeXworks like this:

enter image description here

Running the MWE in the original question, the compiler will compile a separate file main-figure0.pdf with only the TikZ figure, in addition to the full document main.pdf:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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