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>

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.

  • Do you know pdfrack. – Marco Daniel Sep 4 '11 at 17:45
  • 5
    PDF is binary which makes replacing material difficult. You would need to disassemble and reassemble the PDF file in order to insert material which can't be done using pdftex I guess. – Martin Scharrer Sep 4 '11 at 17:48
  • @Marco: Yes, but it is still a workaround. From the package README: The pdfrack.sh script uses a lot of other scripts and software. cut, dvips, epstopdf, grep, head, latex, ps2ps, ps2epsi, sort, tail, and, first of all, a bourne shell... Sorry for Win* users. They should install solutions like Cygwin, or try a Linux distribution. – Werner Sep 4 '11 at 17:51
  • @Werner: Every solution which is listed in the documentation is a workaround. I think Martins comment is the solution. – Marco Daniel Sep 4 '11 at 17:54
  • @Marco: If this is true, "difficult...I guess" should probably be "virtually impossible". I thought, with technical foundations in Postscript and an open file structure, access to elements contained within a PDF would have been developed by now. – Werner Sep 4 '11 at 18:02

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.)

  • 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

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.