[texhax] Problem with the nameref package

José Carlos Santos jcsantos at fc.up.pt
Mon May 19 22:59:41 CEST 2014


On 19/05/2014 19:27, Heiko Oberdiek wrote:

>> \documentclass{book}
>> \usepackage{hyperref}
>> \begin{document}
>> \tableofcontents
>> \chapter[Short title]{A very, very long title}\label{title}
>> See chapter ``\nameref{title}''.
>> \end{document}
>>
>> then the command \nameref{title} gets the short version of the chapter
>> title, whereas I am interested in the long one. Is there a way of
>> forcing the nameref package to behave as I want?
>
> The title for the label is written into the `.aux` file
> => moving argument.
> Therefore it is quite dangerous for a package like `nameref'
> to prefer the long title that might contain fragile stuff.

In my case, that is not a problem, since my chapter titles have no commands.

> Nevertheless I have added this as feature request into my
> ToDo list.

Thank you.

> A workaround:
>
> \documentclass{book}
> \usepackage{hyperref}
>
> \usepackage{nameref}
> \newif\ifnamereflongtitle
> \makeatletter
> \def\@chapter[#1]#2{%
>    \ifnamereflongtitle
>      \NR at gettitle{#2}%
>    \else
>      \NR at gettitle{#1}%
>    \fi
>    \NR at chapter[{#1}]{#2}%
> }
> \makeatother
>
> \begin{document}
> \tableofcontents
> \namereflongtitletrue
> \chapter[Short title]{A very, very long title}\label{title}
> See chapter ``\nameref{title}''.
> \end{document}

Thanks a lot! You are amazing.

Best regards,

Jose Carlos Santos





More information about the texhax mailing list