# pstool not making substitutions (clash with epstopdf)

Update: now it works. The code is:

% !TeX Program = pdfLaTeX+MakeIndex+BibTeX+ShellExtension
\documentclass{article}
\usepackage{pstool}
\usepackage[utf8]{inputenx}
\begin{document}
\begin{figure}
\psfragfig{trial}{\psfrag{[ev]}{$damn$}}
\end{figure}
\end{document}


I don't know why (that's become an habit) but I had to use a freshly downloaded version of trial.eps (and delete all the auxiliary files). Looks like, differently from epstopdf, pstools doesn't add a suffix and it may ruin the original file (but mostly, I don't know). Now I'm going to try to write something more useful and see what bit of complication breaks it.

Update: I have a preamble loading a few packages and, as Ian Thompson suggested, the only one causing problems is epstopdf, which I didn't expect since pstool's documentation states (p. 2): epstopdf and pstool are compatible, but only if epstopdf is loaded first.

Old question:
I'm working on a simple example taken from a previous question.
I use TeXworks on MiKTeX 2.9 and I'm compiling with pdfLaTeX.

The file trial.eps is in a subfolder named graphicxstuff.
I don't use any macro file, just the commands inside \psfragfig.
The pdf output shows the vector image with selectable text, but [MP] hasn't been replaced by $M_A$!
Also, the image has not been resized.

MWE:

\documentclass{article}
\usepackage[utf8]{inputenx}
\usepackage{graphicx}
\graphicspath{{graphicxstuff/}}
\usepackage[update,prepend]{epstopdf}
\usepackage{pstool}
\usepackage[margin=.5in,parindent=1em]{caption}
\begin{document}
\begin{figure}[h!]
\psfragfig*[width=3cm]{graphicxstuff/trial}{%
\psfrag{[Mp]}{$M_A$!}%
}
\caption{This is the caption}
\end{figure}
\end{document}


Not even

 \documentclass{article}
\usepackage[utf8]{inputenx}
\usepackage{pstool}
\begin{document}
\psfragfig{trial}{\psfrag{[Mp]}{A}}
\end{document}


works for me. This time compiling with
(with epstopdf I didn't need to enable the shell extension).

Don't know why (that's an habit by now) but trial.eps seems broken now, irfanview doesn't open it even if it's freshly downloaded from CTAN.

• Could be caused by spaces in the postscript code ... can you make the eps file available for download and add a link to your question? – Ian Thompson Jun 12 '15 at 13:23
• The .eps can be downloaded from ctan.org/tex-archive/macros/latex/contrib/pstool/example – Arch Stanton Jun 12 '15 at 13:29
• Seems to be a clash with the epstopdf package. I have no time to investigate properly now, but will look later if nobody else solves the problem first. – Ian Thompson Jun 12 '15 at 13:45

This situation is complicated: there are a lot of permutations, and the outcome you will get depends not only on whether shell escape is enabled, what packages are loaded (and with what options, and in what order), but also on what you have tried before. The last complication arises because epstopdf and pstool will try to generate pdf versions of your figure, and may behave differently depending on what files are already present.

1. According to the pstool package documentation, you must load epstopdf before pstool. I know you have done this in your example, but it's worth stating it explicitly for the benefit of others who may read this.

2. You must enable shell escape. Without it, pstool doesn't have the permissions it needs to work its magic, so the conversion is performed by epstopdf, which isn't able to deal with psfrag commands.

3. You must not use the prepend option for epstopdf; this seems to stop pstool from working. I'm not sure if this is a bug, but I will put a comment after my answer to alert the package author (I don't know if @ works in answers).

4. I would be inclined to add the option [process=all] to pstool, at least while you are trying to make everything work. Without it, changing the size and then recompiling doesn't have any effect.

The following works on my machine, provided that shell escape is enabled (and regardless of what has been tried before, and what files are present).

\documentclass{article}
\usepackage{graphicx}
\usepackage[update]{epstopdf}
\usepackage[process=all]{pstool}
\begin{document}
\begin{figure}[h!]
\psfragfig[width=7cm]{trial}{\psfrag{[Mp]}{$M_A$!}}
\caption{This is the caption}
\end{figure}
\end{document}


Now, I seem to remember that there is something valuable in a grave marked Arch Stanton. I'd better go and investigate.

• @Will Robertson --- could you please take a look at point 3 here (possible bug in pstool). – Ian Thompson Jun 12 '15 at 18:44
• Don't waste no time, that grave's already been digged, cowboy. The place where the money is is unknown, sorry to disappoint you. – Arch Stanton Jun 12 '15 at 21:30