[Tex/LaTex] Using psfragfig: Error processing graphic

graphics

I am generating an eps and a tex file using matlabfrag, and am trying to include these graphics using pstools as

\begin{figure}[ht]
        \centering
        \psfragfig*[width=0.55\textwidth]{pics/figure1}{}
        \caption{my caption}
\end{figure}

or inside a minipage as

\begin{minipage}{0.55\textwidth}
    \centering
    \psfragfig*[width=0.55\textwidth]{pics/figure1}{}
    \captionof{figure}{my caption}
\end{minipage}

On rare occasions it works just fine (after compiling 100 times), but most of the time I end up with a red frame in the PDF saying "An error occured processing graphic […] check the log file for compilation errors". However, Texniccenter is not giving me any compilation errors, nor can I find any in the log-file of the graphic.

I am using Texniccenter with Miktex 2.9. I am passing the following line to the compiler:

-max-print-line=120 -synctex=1 -interaction=nonstopmode --shell-escape "%wm"

Been stuck on this for days now, any help greatly appreciated!

EDIT: Results from debugging with mode=errorstop as pstool option

There seems to be some problem in the .aux files created. If I delete all .aux files before compiling, the figures are displayed correctly, and there is no error. I can then set \usepackage[process=none]{pstool} and everything is fine.
Compiling the report a second time with [process=all] however triggers errors.

The errors vary depending on where the figures are and how many there are, and how the figures are included, but most of the errors contain a "latex: Bad file descriptor" at some point.
Here is a small selection:

latex: file ended while scanning use of @writefile
! File  ended while scanning us of \@newl@bel
Can't use spacefactor in vertical mode

It looks like the problem arises as soon as I have more than 5 figures spread out in the document. Having more, but all in one place, works fine, so does having e.g. 2 in one place and 3 in the other. I wish I could be more specific, but the errors seem to appear so randomly it's hard to pinpoint anything.

Best Answer

The pstool package uses the error flag of the compilation/typesetting stage to determine if the typesetting has succeeded or not, so if you're seeing that red box there must be an error somewhere in the chain.

To help track down such problems, load pstool with the following option:

\usepackage[mode=errorstop]{pstool}

and use -interaction=errorstopmode in texniccentre; this will show up all output as it comes scrolling through, and will pause when an error occurs.

In the event that the figure typesetting succeeds, this would indicate there's a subsequent problem converting the DVI to PS and then to PDF (and then maybe cropping it). Try and run those steps manually on the pics/figure1.dvi file (or whatever) that results in this case. Since you're using Windows, it's not impossible there's a ghostscript error or something along those lines in the way that pstool is attempting to convert the file.

Related Question