60

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?

Caramdir
  • 89,023
  • 26
  • 255
  • 291
Ma Ming
  • 2,306

1 Answers1

70

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
Caramdir
  • 89,023
  • 26
  • 255
  • 291
  • 1
    Thanks. I figured out this, but it did not work. I use MikTeX 2.9 with updated packages. – Ma Ming Jan 10 '11 at 19:07
  • @MaMing The above works on TeX Live, but I don't have a MikTeX install to test things. Maybe someone else can say why it doesn't work with MikTeX. – Caramdir Jan 10 '11 at 22:18
  • 5
    @MaMing: The problem was in the Windows shell. Apparently chaining commands with ; does not work under Windows. See the updated answer for a solution. – Caramdir Jan 17 '11 at 06:09
  • Thanks for your detailed answer!!! It works for my MikTeX, you helped me too much, thanks again. – Ma Ming Jan 21 '11 at 23:48
  • 2
    Hi when I try your example I'm getting tikz: Sorry, the system call 'latex -halt-on-error -interaction error.

    What seems to be the problem? I'm using MikTex 2.9 and texmakerx on Win 7

    – dingo_d May 12 '11 at 07:46
  • @dingo: I can't really help you with MikTeX, but I suspect that this isn't the full error message. It's probably best to ask a new question, providing a minimal example, the compilation method and the full error message. – Caramdir May 12 '11 at 16:58
  • You should use && instead of ; anyway, because with ; commands will continue to execute even if the previous one failed. – Andrey Vihrov Feb 15 '12 at 19:11
  • How do I remove the suffix from the files? For instance: histogram-figure0.eps ---> histogram.eps – JohnTortugo Nov 14 '13 at 18:11
  • @JohnTortugo: The suffix is automatically appended in case there are several figures in the file. – Caramdir Nov 14 '13 at 18:42
  • i am using Miktex on Windows and did the same as your post, but i only got .ps file, i don't see any .eps file – scmg Jun 30 '15 at 13:12
  • @scmg: You may want to check if ps2eps is installed. Sorry, but I don't use Miktex so I don't know how to check that. – Hoang-Ngan Nguyen Jul 19 '16 at 15:29
  • @Hoang-NganNguyen thanks, i solved the problem already, although i'm not sure if installing ps2eps makes it done or not, since i used GSview to convert .ps to .eps – scmg Jul 20 '16 at 14:04