pst-pdf and beamer conflict

Follow up to this question reporting conflict between [auto-]pst-pdf and hyperref. This is apparently due to the fact that pst-pdf uses preview internally, and preview is currently incompatible with some hyperref mechanisms, as discussed along this page and then this page.

The workaround proposed by Ulrike Fischer currently works for simple cases, but not when including PostScript code within frame environment of the beamer class.

\documentclass{beamer}

\usepackage{pstricks}
\usepackage[pspdf={-dALLOWPSTRANSPARENCY}]{auto-pst-pdf}

\makeatletter
\AtBeginDocument{
\ifpdf\else
\ifPreview
\let\Hy@FirstPageHook\relax
\let\Hy@EveryPageAnchor\relax
\fi
}{}
\fi
}
\makeatother

\begin{document}

\begin{frame}
Some text
\begin{pspicture}(0,0)(5,5)
\psline(0,0)(5,5)
\end{pspicture}
Other text
\end{frame}

\end{document}


Note that only loading the beamer class does not trigger the bug, it's the frame environment that triggers it.

I am looking for a workaround that would allow me to use PStricks in beamer presentations with pdflatex from an up-to-date (2021) texlive.

• it is not a direct incompability with hyperref. preview is not compatible with the new latex shipout code and hyperref is one the cases where you get problems. I have some doubts that the preview maintainer will address this in the near future. I would suggest to either use pstools + pdfcrop or to switch to lualatex. It now supports pstricks through the luapstricks package, and if you run into problems there is an active maintainer. Sep 29 '21 at 20:49
• Many thanks for the tips. I'll first look into pstools before switching engines, which would require much more work. If pdfcrop can replace preview in pstools, do you think it could also do so in pst-pdf? Sep 29 '21 at 21:19
• Looks like pstool does not deal with pspicture environment; it is only designed to work with psfrag, not pstricks. Or did I miss something? Sep 29 '21 at 22:06
• Run the document with lualatex then you do not need pst-pdf Oct 1 '21 at 10:17

You can try the following.

\documentclass{beamer}
\usepackage{pstricks}
\usepackage[pspdf={-dALLOWPSTRANSPARENCY}]{auto-pst-pdf}

\makeatletter

\AtBeginDocument{
\ifpdf\else
\ifPreview
\RemoveFromHook{shipout/firstpage}[hyperref]
\RemoveFromHook{shipout/before}[hyperref]
\fi
}{}
\fi
}
\makeatother
\begin{document}

\begin{frame}
Some text
\begin{pspicture}(0,0)(5,5)
\psline(0,0)(5,5)
\end{pspicture}
Other text
\end{frame}

\end{document}