3:Convert Tikz figures to EPS

Recently one of my paper is accepted to be submitted as a book chapter. The editors ask me to submit both pdf and eps files as they can be easily handled by the publisher.

The typical editing problem starts now:

I’m a big fan of Tikz and all of my figures including plots from Matlab are generated in Tikz files. Since Tikz files are not accepted, it is necessary to create a standalone EPS or PDF file. I was looking for a possible solution to this problem and at last after spending almost two days i found it. So I would like to share the solution with all of you.

http://latex-community.org/forum/viewtopic.php?f=45&t=16218

I’m using Windows 7 and MikTeX. So my blogs and possible latex problems which I encounter will be mainly focused for these specifications. I’ll provide one to two working examples so it makes the life easy rather having compilation errors which I normally encounter when trying different possible solutions on the internet.

Example 1: Create a tex file, e.g., test.tex with the following code

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{external}
\tikzexternalize
\tikzset{external/system call={latex \tikzexternalcheckshellescape
-halt-on-error -interaction=batchmode -jobname “\image” “\texsource” &&
dvips -o “\image”.eps “\image”.dvi}}

\begin{document}
\begin{tikzpicture}
\draw[fill=blue] (0,0) circle (1cm);
\end{tikzpicture}
\end{document}

Now in MS-DOS, you need to select the path where your test.tex file is located. e.g., lets say your file is saved in d drive in a folder name D:\doc\test.tex

  1. Type D: in the command prompt will switch the directory to D drive
  2. Now using cd doc will change the directory to the doc Folder
  3.  Run the following command
    latex -shell-escape test.tex
  4. It will create test-figure0.eps

Example 2: Generating eps files for two figures in a document:

Create a tex file, e.g., test.tex with the following code

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{external}
\tikzexternalize
\tikzset{external/system call={latex \tikzexternalcheckshellescape
-halt-on-error -interaction=batchmode -jobname “\image” “\texsource” &&
dvips -o “\image”.eps “\image”.dvi}}

\begin{document}
\begin{tikzpicture}
\draw[fill=blue] (0,0) circle (1cm);
\end{tikzpicture}
\begin{tikzpicture}
\fill(0,0) rectangle (4,4);
\end{tikzpicture}
\end{document}

By executing latex -shell-escape test.tex command, two eps figures (test-figure0.eps and test-figure1.eps ) will be generated

Example 3: Generate one eps files for both Tikz file. For this purpose you need to combine both figures in one tikzpicture environment and compile the Tex document. The preamble remains same, only the Tikz document is changed

\begin{tikzpicture}
\draw[fill=blue] (0,0) circle (1cm);
\begin{scope}[yshift=-5cm]
\fill(0,0) rectangle (4,4);
\end{scope}
\end{tikzpicture}

Further formatting stuff:

For pdf output, change “latex” to “pdflatex” in the \tikzset setup.

\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape
-halt-on-error -interaction=batchmode -jobname “\image” “\texsource” &&
dvips -o “\image”.eps “\image”.dvi}}

Run

pdflatex -shell-escape test.tex

to generate pdf files.

For ps files, change dvips options in tikzset environment from eps to ps as shown below and run the usual latex command.

\tikzset{external/system call={latex \tikzexternalcheckshellescape
-halt-on-error -interaction=batchmode -jobname “\image” “\texsource” &&
dvips -o “\image”.ps “\image”.dvi}}

Leave a comment