Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

2 Answers 2

up vote 9 down vote accepted

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.

share|improve this answer
    
Those look like great resources -- thanks! –  Kevin Walker Aug 28 '10 at 4:34
    
What does the output of eps2pgf look like? Is it really an operator-by-operator translation, or does it make heavy use of quoting Postscript? –  Charles Stewart Aug 28 '10 at 14:03
1  
I added sample output of eps2pgf to the question above. –  Kevin Walker Aug 28 '10 at 21:27
    
@Kevin: Thanks. That looks nice. –  Charles Stewart Aug 29 '10 at 7:47
add comment

There's also a TikZ exporter plugin for Inkscape you might try. (Inkscape can import EPS/PS and PDFs and other vector formats.)

However, I guess I don't really see how it's more "convenient" to have TikZ code to replace the PDFs, unless you plan on making edits. PS/EPS/PDF images are very easily incorporated into LaTeX.

share|improve this answer
1  
You guessed correctly: I expect to find TikZ more convenient for editing and reuse. In the past I've always used EPS/PDF, but I thought I would give something new a try. –  Kevin Walker Aug 28 '10 at 4:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.