# Using pstool with LuaLaTeX

I am trying to use psfrag in conjunction with pstool an LuaLaTeX to replace a tag in an .eps plot generated with gnuplot. I'm not sure if pstool is generally working with LuaLaTeX, however, the processing of the .eps results in an compilation error because pstool seems to call pdfLaTeX instead:

An error occured processing graphic:
./fig.eps'
Check the log file for compilation errors: ./fig-pstool.log'


And in the fig-pstool.log:

Fatal fontspec error: "cannot-use-pdftex"


MWE:

\documentclass{scrbook}

\usepackage{polyglossia}
\usepackage{fontspec}
\usepackage{graphicx}
\usepackage{epstopdf}

\usepackage{psfrag}
\usepackage{pstool}

\begin{document}

\begin{figure}
\psfragfig*{fig}{\psfrag{SL2}[Br]{$\int_{-1}^1 \rho dh$}}
\end{figure}

\end{document}


Compiling with pdfLaTeX or omitting fontspec works fine.

A sample file for fig.eps can be found at Github.

• Are you sure, that you can compile your code with pdfLaTeX without any changes? Compiling with pdfLaTeX should throw an error when loading polyglossia or fontspec. – lcnittl Dec 12 '17 at 21:47

To my knowledge psfrag/pstool is indeed calling pdfLaTeX to do the ps-magic. The problem why your code is not working is the fact that neither polyglossia (as it internally loads fontspec) nor fontspec are working with pdfLaTeX.

To still be able to use LuaLaTeX and those packages in combination with psfrag/pstool you can utilise the iftex package. Among many others, this package provides a conditional for checking which compiler is processing the tex file.

If you put polyglossia and fontspec in a \ifLuaTeX branch, everything should work nicely (Except for fontspecs font substitution in the psfrag commands).

% !TeX program = lualatex
\documentclass{scrbook}

\usepackage{iftex}
\ifLuaTeX
\usepackage{polyglossia}
\usepackage{fontspec}
\fi
\ifPDFTeX
% Define fonts for pdfLaTeX here
\fi

\usepackage{graphicx}
\usepackage{pstool}

\begin{document}
\begin{figure}
\psfragfig*{fig}{\psfrag{SL2}[Bl]{$\int_{-1}^1 \rho dh$}}
\end{figure}
\end{document}


When running LuaLaTeX you can in this case omit epstopdf. Furthermore, no need to explicitly load psfrag as this is done by pstool.

The reason for the disappeared integral sign is the positioning of the replacement. The replacements can only occur in the area of the (e)ps, everything reaching over its borders will be cut off. To solve this issue, either replace the tag in the eps file or change the substitution's alignment. I changed the [<posn>] from [Br] to [Bl] in the above code, now everything is visible.
• I was indeed using \usepackage{ifthen} \usepackage{ifluatex} to conditionally load fontspec and polyglossia, otherwise babel for pdfLatex execution but probably stripped it while creating the MWE (hard to tell, have moved on to pgfplots long ago). Now the weird part: Running your code with lualatex from the command line works, but the integral sign is missing in the substitution. But compiling it from within texstudio with the same command yields the first error from above in the pdf and ! LaTeX Error: File "pstool.sty"not found.in fig-pstool.log. – Christoph90 Dec 13 '17 at 9:48
• Let's not focus on these texstudio-only errors, these seem to be unrelated configuration problems. I'll provide fig.eps above and maybe we'll fix the integral sign not appearing? – Christoph90 Dec 13 '17 at 9:51
• @Christoph90 Is it possible, that TeXstudio is calling a compiler of another distribution? (Reagrding the "pstool.sty"not found error) – lcnittl Dec 13 '17 at 11:10