TikZ-PGF External – How to Export EPS Figures from TikZ

tikz-externaltikz-pgf

Section 32 Externalization Library of the pgfmanual (v2.10) explains how to generate PDF figures and EPS figures. I successfully tried it with PDF output (there is an example with a full explanation in the manual), but failed with EPS (no example provided). Can anyone give me a minimal example?

Best Answer

The manual says that one way is to run pdftops -eps <pdf file> <eps file> after a compilation that produces a .pdf.

Alternatively, you can use the external/system call=... key as described on page 345 of the v2.10 manual. Unfortunately, the way to do it differs slightly between operating systems and TeX distributions. Here are descriptions for the three most common combinations:


Under unixy operating systems (Linux, Mac OS X) with TeX Live (or derivatives like MacTeX), the following should work:

\documentclass{article}
\usepackage{tikz}

% set up externalization
\usetikzlibrary{external}
\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error
-interaction=batchmode -jobname "\image" "\texsource";
dvips -o "\image".ps "\image".dvi;
ps2eps "\image.ps"}}
\tikzexternalize

\begin{document}
\begin{tikzpicture}
[some graphic]
\end{tikzpicture}
\end{document}

Then you run the file with latex --shell-escape (not pdflatex!).


If you run TeX Live under Windows, the ; in the system call definition has to be changed to && (that change should also work for at least some shells in other OSes).

\documentclass{article}
\usepackage{tikz}

% set up externalization
\usetikzlibrary{external}
\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error
-interaction=batchmode -jobname "\image" "\texsource" &&
dvips -o "\image".ps "\image".dvi &&
ps2eps "\image.ps"}}
\tikzexternalize

\begin{document}
\begin{tikzpicture}
[some graphic]
\end{tikzpicture}
\end{document}

and you should compile it with latex --shell-escape (I haven't tested this myself, but I'm pretty sure that this will work).


If you use MikTeX on Windows, you need to further change --shell-escape to -enable-write18 and tell TikZ about the change:

\documentclass{article}
\usepackage{tikz}

% set up externalization
\usetikzlibrary{external}
\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error
-interaction=batchmode -jobname "\image" "\texsource" && 
dvips -o "\image".ps "\image".dvi &&
ps2eps "\image.ps"}}
\tikzexternalize[shell escape=-enable-write18] % MikTeX uses a -enable-write18 instead of --shell-escape.

\begin{document}
\begin{tikzpicture}
\draw (0,0) circle (1cm);
\end{tikzpicture}
\end{document}

and run with latex -enable-write18 (not pdflatex!).


If you want to run pdflatex and create an .eps file from the image, replace the system call by

pdflatex \tikzexternalcheckshellescape -halt-on-error 
-interaction=batchmode -jobname "\image" "\texsource" && % or ;
pdftops -eps "\image".pdf
Related Question