I would like to convert my TikZ images to EPS format and save in a separate file while pdfLaTeX compiles my document, ideally. Note I am using MikTeX and TeXstudio.

Otherwise, I would like to be able to convert TikZ pictures into EPS from a LaTeX file using pdfLaTeX.

I've tried the method found here but the pictures do not work entirely correctly. There is some cutoff (missing parts of the image), plus it is a pain to convert each figure this way.

Example code below.



\usetikzlibrary{arrows, calc, decorations.pathmorphing, shapes}


    \begin{tikzpicture}[scale=1, font=\normalsize, every node/.append style={transform shape}]
        \node[rectangle, draw, minimum width=1.5em, minimum height=1.5em, line width=0.05em] (n1) at (0,0) {1};
        \node[rectangle, draw, minimum width=1.5em, minimum height=1.5em, line width=0.05em] (n2) at (2,0) {2};     

In the command prompt:

latex --jobname=levels test.tex
dvips -o levels.eps levels.dvi

Any ideas?

  • 2
    Why do you want eps instead of pdf? pdflatex --jobname=levels test.tex will create pdf results not dvi. – Ignasi May 14 '15 at 7:58
  • Some journal papers require figures in eps format rather than pdf format. – The Guy May 14 '15 at 17:34

Based on @Ignasi answer and the link he posted about using an editor with PdfLaTeX, the solution is as follows:

From foolabs.com download xpdf and unpack to a location on your computer.

In Computer Properties Go to Advanced system settings -> Environment Variables and add the path of your particular xpdfbin\bin to the path. This will enable Windows to find the folder and use the executable pdftops on the command line.

In TeXstudio Go to Options -> Commands and change the PdfLaTeX line to this:

pdflatex.exe --shell-escape -synctex=1 -interaction=nonstopmode %.tex

This will tell TeXstudio to use the above on the command line when you hit the compile button for a file.

Finally, in your LaTeX Document, add the following to the preamble:


\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape 
                                        -jobname "\image" "\texsource"
                                        && pdftops -eps "\image.pdf"}}
\tikzexternalize[shell escape=-enable-write18]

Then you can compile to your heart's desire as PdfLaTeX will generate pdf and eps versions of all your Tikz drawings!

Other info for a pertinent LaTeX build and how to do it for your particular case may be found in either of these two links suggested by @Ignasi:

  1. how-to-save-a-figure-produced-by-tikz-save-export-as-eps-file
  2. export-eps-figures-from-tikz

Also, this technique should work using the other tools for Pdf conversion in the xpdf package such as pdftopng.


This is what externalize TikZ library does. Try to compile next code with command pdflatex --shell-escape levels (being levels the name of the file). As a result you'll get a pdf file with the whole document, but also another file called levels-figure0.pdf which contains the TikZ figure:

enter image description here

In fact you'll get as many levels-figureXXX.pdf files as tikzpictures you have in your .tex source. Next time you compile again your source file, all tikzpictures are not processed and replaced by corresponding .pdf results.

If any tikzpicture has been changed in the mean time, it's processed again, but only those which has been updated.

This default behavior can be changed introducing commands and options from externalize library whose information can be found in section "50 externalization library" (pp 597-610) from pgfmanual.





\begin{tikzpicture}[scale=1, font=\normalsize, every node/.append style={transform shape}]
\node[rectangle, draw, minimum width=1.5em, minimum height=1.5em, line width=0.05em] (n1) at (0,0) {1};
\node[rectangle, draw, minimum width=1.5em, minimum height=1.5em, line width=0.05em] (n2) at (2,0) {2};     

  • So the library can recognize if the figure code was changed before to compile it? If not, simply use the pdf figure created before; if yes, compile it again and create the pdf again? – Sigur May 14 '15 at 8:01
  • 1
    @Sigur: After better reading I think it remakes all of them by default. I'll confirm it later and correct my answer. – Ignasi May 14 '15 at 8:40
  • 1
    @Sigur: I've confirmed it. By default only edited figures are recompiled. Although you can change this behavior. – Ignasi May 14 '15 at 11:03
  • 1
    @TheGuy Yes, you can use pdflatex which generates pdf files and convert them with pdftops -eps pdffile epsfile. Or use latex which produces .ps files for every figure. – Ignasi May 15 '15 at 9:41
  • 1
    @TheGuy I think these ones provide better answers than mine: tex.stackexchange.com/questions/91275/… or tex.stackexchange.com/questions/8641/… – Ignasi May 16 '15 at 7:22

As an alternative to using \usetikzlibrary{external} if the document is stable and you will make few modifications to tikzpicture, it is better to handle it in separate files and include them as an image (or with \input{test-tkz.tex}). The ltximg script you can do the following:

$ ltximg  --eps --subenv --imgdir=mypics --prefix=tkz -o test-out test.tex

Now you will have a new document test-out.tex with the tikzpicture environments converted into images (preserving the consistency of the fonts) and you will also have each tikzpicture environment in separate files (in case you need some extra modification) and one file test-all.tex with (only) all tikzpicture.

First check the documentation to see the options and conditions that the input file must meet.

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.