# 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: \documentclass{article} \usepackage{pgf} \begin{document} \input{tiger.pgf} \end{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: theta=0:0.05:5; y=sin(theta.^2); plot(theta,y); ylabel('\tex[cc][]{$y$}') xlabel('\tex[cc][]{$\theta$}') title('\tex[cc][]{$\sin\theta^2$}') text(1,0,'\tex{\LaTeX}') 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 Overleaf]

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. En français: TeXnique.fr.

\documentclass{article}%

\usepackage{tikz}
\begin{document}

\input{tiger.pgf}
% Excerpt from tiger.pgf:
%% Created by Eps2pgf 0.6.0 (build on 2008-02-04) on Fri Apr 18 08:15:18 CEST 2008
%\begin{pgfpicture}
%\pgfpathmoveto{\pgfpoint{0.6cm}{6.033cm}}
%\pgfpathlineto{\pgfpoint{20.002cm}{6.033cm}}
%\pgfpathlineto{\pgfpoint{20.002cm}{26.07cm}}
%\pgfpathlineto{\pgfpoint{0.6cm}{26.07cm}}
%\pgfpathclose
%\pgfusepath{clip}
%\begin{pgfscope}
%\definecolor{eps2pgf_color}{gray}{0.8}\pgfsetstrokecolor{eps2pgf_color}\pgfsetfillcolor{eps2pgf_color}
%\pgfpathmoveto{\pgfpoint{0.6cm}{6.033cm}}
%\pgfpathlineto{\pgfpoint{20.002cm}{6.033cm}}
%\pgfpathlineto{\pgfpoint{20.002cm}{26.07cm}}
%\pgfpathlineto{\pgfpoint{0.6cm}{26.07cm}}
%\pgfpathclose
%\pgfusepath{fill}
% ...

\input{plot.pgf}
% Excerpt from plot.pgf
% ...
%\pgfpathlineto{\pgfpoint{14.967cm}{13.811cm}}
%\pgfpathlineto{\pgfpoint{15.055cm}{14.749cm}}
%\pgfusepath{stroke}
%\end{pgfscope}
%\pgftext[x=5.134cm,y=15.013cm,rotate=90]{$y$}
%\pgftext[x=10.653cm,y=12.223cm,rotate=0]{$\theta$}
%\pgftext[x=10.656cm,y=17.45cm,rotate=0]{$\sin\theta^2$}
%\pgftext[base,left,x=8.02cm,y=14.896cm,rotate=0]{\LaTeX}
%\pgfsetdash{}{0cm}
%\pgfusepath{stroke}
%\end{pgfscope}

\end{document}

• #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.

\begin{pgfpicture}
::::::::::::
\end{pgfpicture}

to

\begin{tikzpicture}[scale=0.65]
::::::::::::
\end{tikzpicture}

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.

hello,

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/main.cgi?file=Examples/Gallery/Gallery

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,

wolf

• #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.