Example: eps2pgf

Published 2008-04-18 | Author: Kjell Magne Fauske

Eps2pgf is a PostScript interpreter that converts EPS figures to PGF code for inclusion in LaTeX documents. The author is Paul Wagenaars.

Eps2pgf is a Java command line tool. Here is an example on how to create a PGF version of the well known PostScript tiger:

$ java -jar eps2pgf.jar tiger.eps -o tiger.pgf

To display the tiger you have to include it in a LaTeX document:


The generated PGF code can be found in the file tiger.pgf.

The most interesting part of eps2pgf is that it allows you to replace text in the EPS figure with arbitrary LaTeX markup. It is in fact an alternative to using tools like PSfrag, and it is even compatible with PSfrag. See the documentation for more details.

One application of eps2pgf is to annotate Matlab plots. Here is an example:


The \tex{...} syntax allows you to insert raw LaTeX code in your figure. After you have saved the above figure as an eps file, you can generate a pgf version using:

$ java -jar eps2pgf.jar plot.eps -m directcopy -o plot.pgf

You can find the generated pgf code in the file plot.pgf. Matlab users may also be interested in the script Mathfig2PGF written by eps2pgf’s author.

The output from eps2pgf is low level pgf commands. This can make it a bit difficult to modify the generated code and to use higher level TikZ commands. The tool seems to be actively developed, so I am sure that future versions will offer tighter integration with TikZ.

Download as: [PDF] [TEX]  •  [Open in writeLaTeX]


Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.



% Excerpt from tiger.pgf:
%% Created by Eps2pgf 0.6.0 (build on 2008-02-04) on Fri Apr 18 08:15:18 CEST 2008
% ...

% Excerpt from plot.pgf
% ...



  • #1 H, February 13, 2009 at 5:18 p.m.

    Is there a way to scale the output (besides opening the original in Inkcape and doing the scaling in advance)?

  • #2 Rethnakaran Pulikkoonattu, April 13, 2009 at 9:44 a.m.

    What I do (to scale)is the following: It is again an outside/edit method

    1) Open the PGF file

    2) Change the environment from 'pgfpicture' to 'tikz'

    That is change the pgfpicture in two places (begin and end) and then put the appropriate scaling.




    This works well for me. Of course you can write a small script to automate from command line,if you have multiple files. Since I do it as and when I require I didn't venture into it.

    Best regards Ratnu http://ratnuu.wordpress.com

  • #3 Mark S. Everitt, May 22, 2009 at 4:57 p.m.

    You can also use a \resizebox. That lets you determine the absolute width or height (or both). You can then wrap it in a figure environment. Check out my `energy level diagram' for an example. I did it for TikZ, but it'll work just as well with pgf.

  • #4 Jared, August 5, 2009 at 4:04 p.m.

    Is there a way to annotate jpeg pictures?

  • #5 wolf, January 14, 2010 at 6:29 p.m.


    How can I generate such a random signal in tikz, I can't find a proper way. (please check the following links for reference)


    www.tug.org/PSTricks/Examples/Gallery/exa001.tex www.tug.org/PSTricks/Examples/Gallery/exa001.png www.tug.org/PSTricks/Examples/Gallery/exa002.png

    Best regards,


  • #6 wolf, January 14, 2010 at 7:35 p.m.

    I found the way to draw random signals, like following

    \draw[samples=50,domain=0:2] plot (\x,{.5*rand});

    sorry for bothering

  • #7 Frank Dordowsky, February 1, 2010 at 9:26 p.m.

    The tools I use do not generate text labels in the eps output, so the conversion with eps2pgf does also not contain text labels. Is there any way to recover the text labels?

    Thanks in advance Frank

  • #8 Kjell Magne Fauske, February 4, 2010 at 6:23 p.m.

    @Frank I doubt that there are tools out there that can recover text labels automatically. They have probable been converted to paths prior to export. You should check your export tools to see if you can change some of the text settings.

Adding comments is currently not enabled.



Preorder discount 35%
coupon code LXCB35

LaTeX Beginners Guide

Limited discount 50%
coupon code tDRet6Y

click here to read whole story

Creative Commons License