13

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}
14

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.

  • 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
8

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.

  • 2
    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
  • Another reason could be to be able to embed the PDF into the source code of a package with filecontents, to avoid the distribution of binary files. – gigabytes Mar 18 '16 at 13:55
  • Another reason could be page layout for beamer styles or similar, where you want to arrange things in a way such that it fits the page layout. Note: One beamer style is typically used for different aspect ratios. – Keinstein Nov 15 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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