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 version will offer tighter integration with TikZ.
Edit and compile if you like:
\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}
Click to download: eps2pgf.tex • eps2pgf.pdf
Open in Overleaf: eps2pgf.tex