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} 
6
  • The odd thing is, I swear that this once worked (just a few days ago) but now it's not.
    – orome
    Commented Jun 7, 2012 at 23:23
  • You can only use psfrag using latex. See Why is there no pdffrag package? I haven't tried things with pstool though.
    – Werner
    Commented Jun 7, 2012 at 23:25
  • @Werner: So I can't use it with my build process, where I have use pdflatex?
    – orome
    Commented Jun 7, 2012 at 23:36
  • Could you be having the \psfragfig and \pstool commands mixed up?
    – Werner
    Commented Jun 7, 2012 at 23:45
  • @Werner: I get the same outcome if I substitute \pstool for \psfragfig in the MWE.
    – orome
    Commented Jun 8, 2012 at 2:54

2 Answers 2

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}
7
  • In order to get that to work I need to enable "shell escape". Is that safe?
    – orome
    Commented Jun 8, 2012 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. Commented Jun 8, 2012 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
    Commented Jun 8, 2012 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
    Commented Jun 8, 2012 at 14:58
  • It seems, that \psfragfig doesn't work properly. It works, when used as in my added example Commented Jun 8, 2012 at 16:09
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .