IACR / latex

Latex classes for IACR publications. We will start with the new journal proposal.
8 stars 1 forks source link

Package `babel` causes issues with PDF bookmark to References section #251

Closed GeeLaw closed 3 weeks ago

GeeLaw commented 3 weeks ago

Package babel is listed as supported. From the current version of iacrdoc.tex, perform the following change:

 \DocumentMetadata{pdfstandard=a-2u,pdfversion=1.7}
 \documentclass{iacrcc}
+
+\usepackage[english]{babel}
+
 \newcommand{\cmd}[2][]{%
   \def\FirstArg{#1}
   \ifx\FirstArg\empty
     \texttt{\textbackslash{}#2}%
   \else
     \texttt{\textbackslash{}#2\{#1\}}%
   \fi
 }

Run

pdflatex iacrdoc
bibtex iacrdoc
pdflatex iacrdoc
pdflatex iacrdoc

The log file contains

pdfTeX warning (dest): name{references} has been referenced but does not exist,
 replaced by a fixed one

and the PDF bookmark "References" will take the user to the top of the PDF, instead of the "References" section.

If babel is not used, the problem goes away.

A workaround is to further make the following change:

 \begin{itemize}
 \item General \LaTeX{} documentation, such as the
   \href{http://mirrors.ctan.org/info/lshort/english/lshort.pdf}{(not
     so) short introduction to \LaTeXe};
 \item The
   \href{https://mirror.mwt.me/ctan/macros/latex/required/amsmath/amsldoc.pdf}{amsmath
     documentation} is useful for learning how to typeset mathematics.
 \end{itemize}

+\makeatletter
+\let\section@bak\section
+\def\section{\@ifstar{\section@bib}{\section@bib}}
+\def\section@bib#1{%
+  \let\section\section@bak
+  \let\section@bib\undefined
+  \section*{#1\Hy@raisedlink{\hypertarget{references}{}}}%
+}
+\makeatother
 \bibliography{biblio}
+\makeatletter
+\let\section\section@bak
+\let\section@bak\undefined
+\let\section@bib\undefined
+\makeatother
 \end{document}
jwbos commented 3 weeks ago

Indeed, this does not seem to work with Babel. I had a look how Babel works and I propose a slightly different solution (see: 1308cb28004a6b60a09de624e800ea74f8f028a5).

\AtEndPreamble{%
  \@ifpackageloaded{babel}{%
    % Ensure the bookmark for the reference points to the section header
    % Insert a PDF anchor into the beginning of \refname
    % Add this to captionsenglish to avoid problems when babel is used
    \addto\captionsenglish{%
      \gdef\refname{\leavevmode\texorpdfstring{\vbox to 0pt{\vss\pdfdest name{references}XYZ\vskip\baselineskip}\relax\oldrefname}{\oldrefname}}%
    }%
  }{}%
}

The idea is to reuse the solution we have but to add this to Babel by adding to \captionsenglish. The downside is that we need to do this for other languages but since the journal is in English I don't expect an issue. @GeeLaw can you test if this resolves your issue? If so, I will merge this change.

jwbos commented 3 weeks ago

Fixed. See: 1308cb28004a6b60a09de624e800ea74f8f028a5