2

I can't get simple psfrag substations go happen, and wonder if I'm missing an option or preference somewhere that will make them work.

I'm using LyX to build by document, but I have the same problem in nearly every tool I try. The only way I've been able to get substitutions to happen is by choosing Typeset > TeX and DVI in TeXShop using a MWE. But that's not were I build my actual document, and I don't think I can (and probably don't want to) make the equivalent change in LyX, where I actually work.

Is there some way I can modify the code below to so that substitutions will occur, using pdflatex (if that's even relevant)?

\documentclass{scrartcl}  
\usepackage{pstool}
\usepackage{psfrag}
\usepackage{tikz}

\begin{document}

\psfragfig*{graphA}{
    \psfrag{X}{$\epsilon$}
} 

\psfragfig{graphA}{
    \psfrag{X}{$\pi$}
} 

\psfragfig!{graphA}{
    \psfrag{X}{Q}
} 

\psfrag{X}{Help}
\includegraphics{graphA}

\end{document} 
orome
  • 10,459

2 Answers2

5

As you know by now, psfrag requires latex->dvips chain and will not work with pdflatex.

A possible (ugly) workaround is to create a minimal document which only includes that figure and uses psfrag to do the replacement of the labels, and compile that document with latex->dvips->pstopdf (or perhaps latex->dvipdfm), to obtain a pdf file containing only that figure. You can use also preview package to create a pdf with a page size that fits exactly the size of the included graphic.

Once you have created the pdf figure this way, you can import it in your "main" file via \includegraphics, and use pdflatex to process that file.

JLDiaz
  • 55,732
5

To get correct typeset psfrag (and pstricks) stuff when compiling tex-->pdf directly, you should use the package auto-pst-pdf, which in a first run creates a file \jobname-pics.pdf, which collects all eps files converted to pdf embedding pstricks stuff.

You only need \usepackage{auto-pst-pdf} in your preamble.
If this -pics.pdf is created an you don't change your pics any more, you may set the option [off] to the call of \usepackage[off]{auto-pst-pdf} to get faster compilation.

To give a working exmaple:

\documentclass{article}
\usepackage{auto-pst-pdf}
\usepackage{graphicx}
\usepackage{psfrag}

\begin{document}

Some text

{
\psfrag{P1}{$P_1$}\psfrag{a}{\alpha}
\includegraphics[width=0.5\textwidth]{TestEps}
}

{
\psfrag{P1}{$Q=P_1$}
\includegraphics[width=0.5\textwidth]{TestEps}
}

\end{document}
Andrew Swann
  • 95,762
  • In order to get that to work I need to enable "shell escape". Is that safe? – orome Jun 08 '12 at 13:35
  • @raxacoricofallapatorius This is often needed, even when translating with lualatex. I think it's harmless when you compile your own code. But when you compile foreign code then it might be that something could be executed you didn't want. – Peter Breitfeld Jun 08 '12 at 14:22
  • When I try this (in LyX) using my full document (not just the MWE) it takes forever (10 minutes, even if I import no EPSs) and then fails. If I turn auto-pst-pdf off (with the off package option), things are fine. Are there package interactions I should avoid? Everything (else) worked fine before adding austo-pst-pdf. – orome Jun 08 '12 at 14:48
  • Clarification: "fails" means no graphic is produced in the final document or, sometimes, the rendering fails completely (perhaps because of a timeout). – orome Jun 08 '12 at 14:58
  • It seems, that \psfragfig doesn't work properly. It works, when used as in my added example – Peter Breitfeld Jun 08 '12 at 16:09
  • Part of my problem seems to be related to microtype. – orome Jun 09 '12 at 04:21
  • As per Will Robertson, http://tex.stackexchange.com/a/11844/15717 pstool is more apt for psfrag applications. auto-pst-pdf for pstricks. 'pstool' is much faster way for using psfrag with pdflatex – texenthusiast Jul 07 '12 at 19:55