Include pdf through includegraphics breaks pstricks/auto-pst-pdf

auto-pst-pdfincludegraphicspstricks

EDIT: problem was coming from a borked installation of texlive on Opensuse (some packages were not updated, so texlive was a mix of 2017 and 2021).

It seems newer versions of pstricks and/or (pdf)latex break when including a pdf via includegraphics and using pstricks code, unless the includegraphics is hidden inside a \ifpdf … \fi block. This had always worked until I updated texlive recently.

Here is a minimal example:

\documentclass[10pt]{article}
\usepackage{ifpdf}
\usepackage{pst-all}
\usepackage[on]{auto-pst-pdf}
\begin{document}

%\ifpdf
\includegraphics[height=3.5cm]{some_pdf_file.pdf}
%\fi

\begin{postscript}
\begin{pspicture}(0,0)(18,10)
\pspolygon[fillstyle=solid,fillcolor=lightgray,linewidth=0](0,3)(0,0)(3,0)(3,3)
\end{pspicture}
\end{postscript}
\end{document}

compiling this with pdflatex –shell-escape produces the following error:

Error: /undefined in obj
Operand stack:
   1   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1974   1   3   %oparray_pop   1973   1   3   %oparray_pop   1961   1   3   %oparray_pop   1817   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:736/1123(ro)(G)--   --dict:0/20(G)--   --dict:191/200(L)--   --dict:97/300(L)--   --dict:45/200(L)--
Current allocation mode is local
Current file position is 146540
GPL Ghostscript 9.52: Unrecoverable error, exit code 1
system returned with code 256
PDFCROP 1.40, 2020/06/06 - Copyright (c) 2002-2020 by Heiko Oberdiek, Oberdiek Package Support Group.

!!! Warning: Empty Bounding Box is returned by Ghostscript!
!!!   Page 1: 0 0 0 0
!!! Either there is a problem with the page or with Ghostscript.
!!! Recovery is tried by embedding the page in its original size.

whereas the error disappears after uncommenting the \ifpdf and \fi .

Best Answer

I have no problem with

\documentclass[10pt]{article}
\usepackage{pst-all}
\usepackage[pspdf={-dNOSAFER -dALLOWPSTRANSPARENCY}]{auto-pst-pdf}
\begin{document}

\includegraphics[height=3.5cm]{tiger.pdf}

\begin{pspicture}(0,0)(18,10)
\pspolygon[fillstyle=solid,fillcolor=lightgray,linewidth=0](0,3)(0,0)(3,0)(3,3)
\end{pspicture}
\end{document}

However, running it with lualatex (needs an up-do-date TeX distribution) makes life easier ....

\RequirePackage{pdfmanagement-testphase}% needed for transparency
\DeclareDocumentMetadata{}
\documentclass[10pt]{article}
\usepackage{pst-all,graphicx}
\begin{document}

\includegraphics[height=3.5cm]{tiger.pdf}

\begin{pspicture}(0,0)(3,3)
\pspolygon[fillstyle=solid,fillcolor=lightgray,linewidth=0](0,3)(0,0)(3,0)(3,3)
\end{pspicture}
\end{document}

enter image description here

Related Question