4

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
2

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.

Edit (See comments)

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.

[Bl] alignment

  • 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
  • @Christoph90 Edited the answer. – lcnittl Dec 13 '17 at 11:21
  • Thanks for the updated answer. Working fine now from the command line! I dug around my old files from 2014 but could not find a logfile to check the compiler invocations to verify what my original mistake was. Anyway, for the present errors I get from within TeXstudio, I don't think it's another distribution since I only have tl2017 installed and call lualatex with absolute path from TeXstudio and the command line... – Christoph90 Dec 13 '17 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.