[Tex/LaTex] PS-or-PDF to tikz converter

tikz-pgf

It is often the case that a postscript or PDF image used in a math paper consists mainly of a few lines and bezier curves. If there were an easy way to extract this information and convert it into tikz \draw commands, one could conveniently replace existing included graphics with tikz pictures. Does anyone know of a conversion program which does this? It would not need to be a completely general solution — if it extracted a majority of the useful information (lines, curves, labels(?), …) from a majority of the files it was presented with, that would be quite useful.


ADDED:

One of the commenters asked what the output of eps2pgf looks like. Here's a sample:

% Created by Eps2pgf 0.7.0 (build on 2008-08-24) on Sat Aug 28 14:14:16 PDT 2010
\begin{pgfpicture}
\pgfpathmoveto{\pgfqpoint{0cm}{0cm}}
\pgfpathlineto{\pgfqpoint{5.186cm}{0cm}}
\pgfpathlineto{\pgfqpoint{5.186cm}{4.092cm}}
\pgfpathlineto{\pgfqpoint{0cm}{4.092cm}}
\pgfpathclose
\pgfusepath{clip}
\begin{pgfscope}
\pgfpathmoveto{\pgfqpoint{0cm}{4.092cm}}
\pgfpathlineto{\pgfqpoint{0cm}{0cm}}
\pgfpathlineto{\pgfqpoint{5.186cm}{0cm}}
\pgfpathlineto{\pgfqpoint{5.186cm}{4.092cm}}
\pgfpathclose
\pgfusepath{clip}
\begin{pgfscope}
\begin{pgfscope}
\pgfsetdash{}{0cm}
\pgfsetlinewidth{0.317mm}
\definecolor{eps2pgf_color}{rgb}{0,0,0}\pgfsetstrokecolor{eps2pgf_color}\pgfsetfillcolor{eps2pgf_color}
\pgfpathmoveto{\pgfqpoint{0.044cm}{2.586cm}}
\pgfpathcurveto{\pgfqpoint{0.789cm}{2.747cm}}{\pgfqpoint{1.394cm}{3.29cm}}{\pgfqpoint{1.633cm}{4.014cm}}
\pgfusepath{stroke}
\end{pgfscope}
\begin{pgfscope}
\pgfsetdash{}{0cm}
\pgfsetlinewidth{0.317mm}
\definecolor{eps2pgf_color}{rgb}{0,0,0}\pgfsetstrokecolor{eps2pgf_color}\pgfsetfillcolor{eps2pgf_color}
\pgfpathmoveto{\pgfqpoint{3.538cm}{4.014cm}}
\pgfpathcurveto{\pgfqpoint{3.629cm}{3.205cm}}{\pgfqpoint{4.31cm}{2.592cm}}{\pgfqpoint{5.125cm}{2.586cm}}
\pgfusepath{stroke}
\end{pgfscope}
\begin{pgfscope}
\pgfsetdash{}{0cm}
\pgfsetlinewidth{0.317mm}
\definecolor{eps2pgf_color}{rgb}{0,0,0}\pgfsetstrokecolor{eps2pgf_color}\pgfsetfillcolor{eps2pgf_color}
\pgfpathmoveto{\pgfqpoint{0.046cm}{4.015cm}}
\pgfpathlineto{\pgfqpoint{5.126cm}{4.015cm}}
\pgfpathlineto{\pgfqpoint{5.126cm}{0.046cm}}
\pgfpathlineto{\pgfqpoint{0.046cm}{0.046cm}}
\pgfpathclose
\pgfusepath{stroke}
\end{pgfscope}
\begin{pgfscope}
\pgfsetdash{}{0cm}
\pgfsetlinewidth{0.317mm}
\definecolor{eps2pgf_color}{rgb}{0,0,0}\pgfsetstrokecolor{eps2pgf_color}\pgfsetfillcolor{eps2pgf_color}
\pgfpathmoveto{\pgfqpoint{0.046cm}{1.316cm}}
\pgfpathlineto{\pgfqpoint{5.126cm}{1.316cm}}
\pgfusepath{stroke}
\end{pgfscope}
\end{pgfscope}
\end{pgfscope}
\end{pgfpicture}

Best Answer

You can try eps2pgf, it seems to be written for exactly this purpose. I have never tried it, so I am not sure how well it works.

Another option could be using pstoedit to convert your postscript to an editable format like gnuplot, xfig or svg, and convert that to tikz using an appropriate tool.

Number of tools that generate pgf/tikz code are described here.