[Tex/LaTex] What does psfrag do, and can it be made to work with pdflatex

psfrag

I'm picking up a document, thus far, created by someone else who is unavailable for questioning.

I have a vague idea what is trying to be accomplished with this:

\clearpage
\begin{figure}[h!]
\psfrag{F}{$F_c$}
\psfrag{M}{$M_0$}
\psfrag{V}{$V$}
\psfrag{Y}{$Y$}
\psfrag{X}{$X$}
\psfrag{T}{Thin film}
\psfrag{A}{Adhesive layer}
\psfrag{R}{Rigid surface}
\includegraphics{figure1a}
\end{figure}

(there are 2 more figures, b and c then)

"Fig. 1 Schematic description….." for a bottom of the page caption.

I can latex it without error, but when I try to pdfltex … it I get an error message that states:

I could not locate the file with any of the extensions: .png, .pdf, .jpg, .mps, .jpg, .jbig2, .jb, .PNG, .PDF, .JPG, .JPEG, .JBIG2, .JB2 Try typing <return> to proceed.

After latex, xdvi file displays the desired figure, but there is text scrunched up on the left of the page, to the left of the figure partially revealing "F_c" (in the proper format) through X on successive lines, then "Thin film, Adhesive layer", then "Rigid surface". To the right of the figure is the figures' designator letter (a).

Just above to figure in the left margin above "F_c" is a cut-off word, ending ing 'g', I think "g replacements".

When I pdflatex in order to create a PDF file, then getting the aforementioned error message, I just , through it. The resulting PDF is a blank page, save for the figures' letter designators, (a), (b), and (c) in a column down the center of the page with the "Fig.1…" caption at the bottom of the page.

The figure1a is in the same directory as the document files as figure1a.fig in addition to a figure1a.eps.

I've been able to come up with scant little help in the Leslie Lamport book.

Can you tell me what the psfrag business is all about?

I've imported figures in my own documents, but not in this fashion. I hate to re-tool this one if I can create something better and learn a new technique in the process.

Best Answer

The psfrag package is used to remove labels and other text from .eps graphics and replace them with LaTeX labels. This can be used to ensure that fonts in figures are consistent with those in the main body of the document, regardless of whether your graphics software can access them. It is particularly useful for inserting formulae and symbols, since a label in the eps file can be replaced by (more or less) arbitrary LaTeX code. In this example, the word 'typography' is replaced by an italic version in the current font.

\documentclass{article}
\usepackage{graphicx}
\usepackage{psfrag}
\begin{document}
\begin{center}
\includegraphics[width=70pt]{small}
\end{center}
\begin{center}
\psfrag{typography}{\textit{typography}}
\includegraphics[width=70pt]{small}
\end{center}
\end{document}

The file 'small.eps' is as follows:

%!PS-Adobe-2.0 EPSF-2.0
%%Title: test.eps
%%BoundingBox: 0 0 100 50
/Times-Roman findfont
15 scalefont
setfont
20 20 moveto
(typography) show
showpage
%EOF

frag

However, as you have discovered, psfrag only works if you compile via latex -> dvips -> ps2pdf; it won't work with pdflatex. There is a package called pstool which works around this problem. Provided that shell escape is enabled, this version of the example will work with pdflatex.

\documentclass{article}
\usepackage{pstool}
\begin{document}
\begin{center}
\includegraphics[width=70pt]{small.eps}
\end{center}
\begin{center}
\psfragfig*[width=70pt]{small}{\psfrag{typography}{\textit{typography}}}
\end{center}
\end{document}