Labelling graphics

“Technical” graphics (such as graphs and diagrams) are often labelled with quite complex mathematical expressions: there are few drawing or graphing tools that can do such things (the honourable exception being MetaPost, which allows you to program the labels, in (La)TeX, in the middle of specifying your graphic).

Labels on graphics produced by all those other tools is where the psfrag package can help. Place an unique text in your graphic, using the normal text features of your tool, and you can ask psfrag to replace the text with arbitrary (La)TeX material. Psfrag’s “operative” command is \psfrag{PS text}{Repl text}, which instructs the system to replace the original (“PS”) text with the TeX-typeset replacement text. Optional arguments permit adjustment of position, scale and rotation; full details may be found in pfgguide in the distribution.

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.

On the other hand, VTeX’s GeX processor explicitly deals with psfrag, both in its free and commercial instances.

The psfragx package goes one step further than psfrag: it provides a means whereby you can put the psfrag commands into the preamble of your EPS file itself. Psfrag has such a command itself, but deprecates it; psfragx has cleaned up the facility, and provides a script laprint for use with Matlab to produce appropriately tagged output. (In principle, other graphics applications could provide a similar facility, but apparently none does.)

Emacs users may find the embedded editor iTe a useful tool for placing labels: it’s a (La)TeX-oriented graphical editor written in Emacs Lisp. You create iteblock environments containing graphics and text, and may then invoke iTe to arrange the elements relative to one another.

Another useful approach is overpic, which overlays a picture environment on a graphic included by use of \includegraphics. This treatment lends itself to ready placement of texts and the like on top of a graphic. The package can draw a grid for planning your “attack”; the distribution comes with simple examples.

Pstricks can of course do everything that overpic can, with all the flexibility of PostScript programming that it offers The pstricks web site has a page with several examples of labelling which will get you started; if pstricks is an option for you, this route is worth a try.

The confident user may, of course, do the whole job in a picture environment which itself includes the graphic. I would recommend overpic or the pstricks approach, but such things are plainly little more than a convenience over what is achievable with the do-it-yourself approach.

auto-pst-pdf.sty
macros/latex/contrib/auto-pst-pdf (or browse the directory); catalogue entry
iTe
support/ite (or browse the directory); catalogue entry
laprint
Distributed with macros/latex/contrib/psfragx (or browse the directory); catalogue entry
overpic.sty
macros/latex/contrib/overpic (or browse the directory); catalogue entry
psfrag.sty
macros/latex/contrib/psfrag (or browse the directory); catalogue entry
psfragx.sty
macros/latex/contrib/psfragx (or browse the directory); catalogue entry
pstricks.sty
graphics/pstricks (or browse the directory); catalogue entry
pst-pdf.sty
macros/latex/contrib/pst-pdf (or browse the directory); catalogue entry

This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=labelfig