latex3 / hyperref

Hypertext support for LaTeX
159 stars 33 forks source link

With pdfpages' \includepdf, \nameref inserts the name of the chapter that includes the PDF, rather than the name of the section created using \includepdf[addtotoc] #290

Closed kbloom closed 11 months ago

kbloom commented 1 year ago

In my document at https://github.com/kbloom/sheetmusic/blob/pdfs/songbook.tex, I'm using \includepdf with the addtotoc option to include individual pieces of sheet music in a book, and include them in the TOC at the section level, with assigned titles. Elsewhere in the document, I'm using \nameref to try to refer to some of these pieces by name (as well as by page number). In texlive version 63035 (a pdf that I generated on January 15, 2023), the \nameref commands insert the name of the piece sheet music, which I assigned in the addtotoc call. In texlive version 66587 (a PDF I generated today), the \nameref commands insert the name of the chapter that contains the PDF.

Any idea what's wrong here?

u-fischer commented 1 year ago

This is something that should be reported to the maintainer of the memoir class. In memhfixc.sty the class redefines \label and \nameref. The last redefinition is the problem here. In texlive 2021 it wasn't a problem, as hyperref changed the definition again, but now the packages are loaded in a different order and the memoir definition harms.

A small example would be

\documentclass[]{memoir}
\usepackage{pdfpages}
\usepackage{hyperref}
\newcommand{\song}[2]{\includepdf[addtotoc={1,section,1,#1,#2}]{#2}}
\newcommand{\songref}[1]{\nameref{#1}, page \pageref{#1}}

%\makeatletter 
% \RenewDocumentCommand\nameref{s}
%    {\IfBooleanTF{#1}{\@namerefstar}{\T@nameref}}
%\makeatother    
\begin{document}\ShowCommand\nameref
\tableofcontents
\chapter{abc}
\song{Yom Zeh Shiru La'el}{example-image.pdf}
\songref{example-image.pdf}

\end{document}
daleif commented 11 months ago

This is fixed in the next memoir update where we replace the memoir title referencing stuff with native nameref and specific support for it.

u-fischer commented 11 months ago

The new version of memoir is now on ctan and in texlive. So I close here.