I realize that over the past few years, there have been a lot of issues with getting preview to work with hyperref (see here and Ulrike Fisher's question to reference a couple). When using chemnum to auto-number TMP tags in a .eps file (namely from ChemDraw), using the following code was suggested to work:
\makeatletter
\ifpdf
\def\@tempa{off}
\ifnum\pdf@shellescape=\@ne\relax
\ifnum\pdf@strcmp
{\pdf@filemoddate{\jobname.tex}}
{\pdf@filemoddate{\jobname-pics.pdf}}
>0 \relax
\def\@tempa{on}
\fi
\fi
\PassOptionsToPackage{\@tempa}{auto-pst-pdf}
\else
\disable@package@load{hyperref}{}
\disable@package@load{bookmark}{}
\fi
\makeatother
This works with a MWE, and also with every other package I am using (chemistry related and not). However, due to graduate school dissertation requirements, this fix was not working with the custom .sty file. Because this custom .sty includes hyperref, compilation alsways resulted in the GPL Ghostscript 10.02.1: Unrecoverable error, exit code 1 error as found in many cases. Whether the aforementioned code was placed in this file or not, hyperref was continually causing errors.
My only workaround is to move all hyperref options into the preamble of the main .tex rather than burying it into a package. Is this bad practice?
A MWE for using the chemnum package to automatically number ChemDraw files that have been saved as .eps files (with text embedding turned on) is as follows:
\documentclass[]{book}% I'm writing a dissertation after all
\usepackage{auto-pst-pdf}
\makeatletter
\ifpdf
\def@tempa{off}
\ifnum\pdf@shellescape=@ne\relax
\ifnum\pdf@strcmp
{\pdf@filemoddate{\jobname.tex}}
{\pdf@filemoddate{\jobname-pics.pdf}}
>0 \relax
\def@tempa{on}
\fi
\fi
\PassOptionsToPackage{@tempa}{auto-pst-pdf}
\else
\disable@package@load{hyperref}{}
%\disable@package@load{bookmark}{}
\fi
\makeatother
\usepackage{chemnum}
\usepackage{hyperref}
\begin{document}
\begin{figure}
\replacecmpd[]{1}%tag defaults to TMP and should include a number at the end
\includegraphics{examplefigure.eps}
\end{figure}
\end{document}
I'm not entirely sure if it counts as a MWE without the examplefigure.eps file attached, but you can just use your favorite one.
Just for completeness, I use pdflatex.exe -synctex=1 -interaction=nonstopmode -shell-escape %.tex on TeXStudio with TeXLive2023.
Is this bad practice to bring a package such as hyperref from a custom package into the preamble itself? Is there a better option?
hyperrefcode from the shipout hooks seems to fix this issue, until I try to use a .png in a different figure. If there's a.pngin the document, I get the dreadedFloat(s) losterror. – bbarden Mar 05 '24 at 13:12