# How can I avoid manual deletion of all helper files when I use psfrag?

I have a problem in getting pstool to work with \psfragfig.

I have a folder structure that looks as follows:

main.tex
images/
|
|-testeps.eps


The MWE is shown below. All the packages are included for completeness as that reflects the custom, university provided class file I use. In that class file some other commands are included but those are mostly related to the customisation of the headers and titles and therefore omitted.

\documentclass[a4paper,11pt,twoside,onecolumn,openright]{book}

% Packages found in the class (.cls) file
\RequirePackage{fncychap}
\RequirePackage{ifthen}
\RequirePackage{ifpdf}
\RequirePackage{hyperref}
\RequirePackage{colortbl}
\RequirePackage{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{graphicx}
\RequirePackage{eso-pic}
\RequirePackage{psfrag}
\RequirePackage{nomencl}
\RequirePackage{subfig}
\RequirePackage{caption}

\usepackage{pdfsync}                % enable tex source and pdf output syncronicity
\usepackage{natbib}                 % fancy citations
\usepackage{amsmath}                % enables no-number equations {equations*}
\usepackage{tikz}                   % needed to import .tikz graphics
\usepackage{pgfplots}               % needed to import .tikz graphics
\usetikzlibrary{plotmarks}          % needed for tikz scatter plot
\usepackage[section]{placeins}      % keeps figures from floating out of a
\usepackage{pstool}                 % necessary for psfrag with pdflatex

\DeclareGraphicsExtensions{.pdf,.png,.jpg,.eps} %graphicsx package set-up

\begin{document}

Text.

\psfragfig*[width=0.8\linewidth]{images/testeps}
{
\psfrag{A}{$flatplate_2$}
\psfrag{B}{$Plate_2$}
\psfrag{C}{$\gamma$}
}

\end{document}


This MWE compiles fine the first time, but when I try it a second time the output looks like this:
The log file has the following error line in it:

! LaTeX Error: Cannot determine size of graphic in testeps.pdf (no BoundingBox)


I have to manually delete all the files except for the .eps file in the images folder before it works again.

Obviously I don't want to delete all the files manually each time before every re-run, so how can I solve this problem?

I use TeXShop 3.24 on Mac OSX.

Update 1:

It seems that pstool trips over the presence of the .pdf file after it has run the first time. After a first run the image folder contains the following files:

testeps-pstool.aux
testeps-pstool.out
testeps-pstool.pdfsync
testeps.eps
testeps.pdf


If I delete the .pdf file and rerun, all goes well.

Update 2:

It seems that the line

\DeclareGraphicsExtensions{.pdf,.png,.jpg,.eps} %graphicsx package set-up


was giving problems. Removing that line solves my problem.

• Hop this \usepackage[cleanup={.tex, .dvi, .ps, .pdf, .log}]{pstool} works, but make sure which files you need before adding the extensions. – texenthusiast Oct 17 '13 at 0:51
• The cleanup argument doesn't work. On the first run it now prints the text .dvi .ps .pdf .log after the image, and on the second run the same error appears. – Saaru Lindestøkke Oct 17 '13 at 7:43

• With pstool it loads graphicx and psfrag. Make a simple MWE by removing unnecessary packages to demonstrate the error.

• The \DeclareGraphicsExtensions{.pdf,.png,.jpg,.eps} need not be used since pdflatex knows which format to pick during a psfrag auxillary processing(latex->dvips->ps2pdf).

• On TeXLive distro .eps files are also included via epstopdf automatically(under hood) but in MiKTeX it needs to included explicitly in preamble.

• The following example uses EPS figure trial.eps at ctan and more examples at ctan

% compiled by pdflatex --shell-escape enabled
\documentclass{book}
\listfiles % to show the list of packages loaded in .log file
\usepackage[crop=pdfcrop,process=all,cleanup={.tex,.dvi,.ps,.pdf,.log}]{pstool}
% Good options for pstool package
\EndPreamble % Will help to pick the right preamble in pstool auxillary process
\usepackage{color}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.8\linewidth]{trial.eps}
\caption{Tagged eps image}
\end{figure}
\begin{figure}
\centering
\psfragfig[width=0.8\linewidth]{trial}{\color{red}
\psfrag{[Mp]}{$M_A$}%
\psfrag{[hb]}{$H_B$}}
\caption{Replacing tags with real labels with psfrag}
\end{figure}
\end{document}