To use psfrag
with pdflatex I use the pstool
package. Using TeXShop 3.25 I can compile the two minimal working examples given in this and this answer when I use the regular LaTeX typesetter.
The MWE from the first answer looks as follows:
% 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}
And the MWE from the second answer is:
\documentclass{article}
\usepackage{color}
\usepackage{pstool}
\def\a{A}
\EndPreamble
\begin{document}
\psfragfig*[mode=nonstop]{trial}{%
\color{red}
\tiny
\psfrag{[Mp]}{$M_\a$!}%
}
\end{document}
When I use the pdflatexmk
script – which I have modified according to this answer to include the shell escape option required by pstool
– the compilation of both the aforementioned examples always ends in this error message:
Latexmk: Maximum runs of pdflatex reached without getting stable files
Latexmk: Did not finish processing file 'trialctan2.tex':
'pdflatex' needed too many passes
Latexmk: Use the -f option to force complete processing,
unless error was exceeding maximum runs of latex/pdflatex.
Latexmk: applying rule 'pdflatex'...
Latexmk: All targets (trialctan2.pdf) are up-to-date
Why is this error happening and how can I get rid of it?
I tried adding the -f
option to the pdflatexmk
script as follows:
"${LTMKBIN}"/latexmk -pdf -r "${LTMKEDIT}/latexmkrcedit" -r "${TSBIN}/pdflatexmkrc" -f -pdflatex="pdflatex --shell-escape %O %S" "$1"
But the same error persists.
Update 1:
Digging around I found that the culprit is the process=all
option. In the second MWE it is locally enabled by the asterisk after psfragfig
.
With this option the pdf file for each eps figure is recreated on every run. I suspect that the pdflatexmk
script notices this and decides it needs to run again as something has changed, triggering a new eps to pdf conversion, noticing it again, etc…
I think I need to find out how to restrict the process=all
option to the first run only.
Best Answer
The problem is that the file
trial.pdf
is created on every run, and it is always different from the previous version. Sincelatexmk
notices the change, it presumes thatpdflatex
has to be run again. Near the end of its output is the reason:This is just above the output that is quoted in the question.
Possible solutions:
The changes are irrelevant to the final output, so you have to tell
latexmk
to ignore them. This can be done by adding the following line to an appropriatelatexmkrc
file:However, there remains the problem that with the posted MWE the
.pdf
file is recreated on every run ofpdflatex
, whether or not it is needed, which can be excessively time consuming.Alternatively, you can stop
pstool
from recreatingtrial.pdf
on every run by replacingprocess=all
byprocess=auto
in the options list forpstool
in the first example. In the second example you remove the*
after\psfragfig
. But this won't update the pdf file if thepsfrag
substitutions are changed; the only updates are when the.eps
file changes.Another solution is to delegate the making of the
.pdf
file tolatexmk
. For this you should turn off the use of the-shell-escape
option topdflatex
. To make this work needs a bit of trickery in alatexmkrc
file. Here is appropriate code to put into one of thelatexmkrc
files:Note: When using this solution, it is a good idea to invoke the
pstool
package in the mainlatex
document byThis will ensure that if you do happen to invoke
pdflatex
with the-shell-escape
option, it won't interfere too much with the work thatlatexmk
does.