Sep 042007
 

One of the things that frustrated me last year as I edited my honours thesis was text elements in inserted graphs. Axis and tick labels were unavoidable, but making them look consistent with the document text was not easy. I wish that I had found this article about making plots using Octave, gnuplot, and LaTeX, because the psfrag package provides a perfect solution.

It replaces text in an eps file with its own LaTeX formatted text. This allows, for instance, elaborate mathematical formulae to be displayed anywhere on the graph. It also allows axis and tick labels to be replaced with text that exactly matches the font and size used throughout the document – even if document wide settings are changed after the graph has been created.

Since it relies on PostScript magic, it requires eps files. A clever script has been written to essentially allow the psfrag package to be used with pdflatex. I think I might have a more up to date tetex package than the author wrote his script for, however, as I had some difficulty with relative paths and had to add the option “-R0” (that’s a zero) to the dvips command in line 197 to make it work.

For reference, the psfrag package is used as follows. Firstly it must be loaded, so the preamble needs to include: \usepackage{psfrag}
The syntax of the “psfrag” command is: \psfrag{tag}[<posn>][<psposn>][<scale>][<rot>]{replacement} and any number of these lines may be included inside the \begin{figure} section and before the \includegraphics command.To get the required output, a dvi file must be produced: latex FILE.tex and then converted to PostScript: dvips -o FILE.ps FILE.dvi This can then be converted to a pdf using ps2pdf.

It is also possible to use psfrag with LyX. The \usepackage command must be manually added to the preamble (Document->Settings), but within LyX the \begin{figure} and \includegraphics commands are automatically added by using a figure float and inserting an image. The \psfrag commands can be added as TeX code inside the float and above the figure.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)