11

The psfrag package has been around for more than a decade* and is easy to use:

\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{psfrag}% http://ctan.org/pkg/psfrag
...
\psfrag{<tag>}{<LaTeX text>}% <tag> -> <LaTeX text>
\includegraphics{image}

The drawback is the required latex->dvips->ps2pdf route of compilation for output to be produced in PDF format. Why is there no such easy/straight-forward counterpart for this under pdflatex? That is, by replacing all psfrag references to pdffrag in the above code extract.

* psfrag version 3.04 on CTAN is dated 11 April 1998.

Werner
  • 603,163

1 Answers1

13

First, a bit of background. With traditional (La)TeX, including an EPS file is relatively straight-forward at the TeX end. The approach taken by LaTeX is to read the EPS (a text file) to find the bounding box, then leave enough space for this to appear in the output. A link is included in the DVI file using a \special, and the TeX engine is done. Actually rendering the EPS file is then left to the driver.

What psfrag does is include an additional header to be read as part of the EPS file loading, along with the search-and-replace material to actually make the change. So the work is still not done by TeX.

Switching to pdf(La)TeX, directly generating a PDF means writing a PDF file. That requires the appropriate engine support, but more importantly has to include PDF graphics in the correct way. Unlike the EPS format, it's not possible to 'slip in' a header to do replacement within any included PDF files. Thus it would require engine support (a primitive) to do any replacement in a PDF. (There's also the fact that PDF files are not purely text, unlike EPS files, so a simple search-and-replace operation is not really possible.)

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • 1
    quoth the uktug faq: since psfrag works in terms of (encapsulated) PostScript files, it needs extra work for use with PDFLaTeX. The pst-pdf package can support such usage. In fact, the pst-pdf support package auto-pst-pdf offers a configuration setting precisely for use with psfrag...which sounds similar to pdfrack, except with more self-confident authors(!) – wasteofspace Jul 12 '13 at 10:20
  • @wasteofspace: pdfrack has a new home on CTAN. – Werner Jul 10 '15 at 16:22