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.
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}
Comments
Is there a way to scale the output (besides opening the original in Inkcape and doing the scaling in advance)?
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.
to
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
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.
Is there a way to annotate jpeg pictures?
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
I found the way to draw random signals, like following
\draw[samples=50,domain=0:2] plot (\x,{.5*rand});
sorry for bothering
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
@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.