2

How can I get the \nameref command of the hyperref package to work while the enumitem package is loaded? The following gives an error while removing the enumitem fixes it.

\documentclass{article}

\usepackage{enumitem}
\usepackage{hyperref}

\begin{document}

\begin{description}
  \item [{Test\label{Test}}] Some text
\end{description}

\nameref{Test}

\end{document}

I tried to change the order of the packages but that does not help either.

0

2 Answers 2

4

Something like this should work.

\documentclass{article}

\usepackage{enumitem}
\makeatletter
\newcommand\enit@descriptionlabel@hook[1]{}
\def\enit@description@i#1#2#3#4{%
  \ifnum#1>#3\relax
    \enit@toodeep
  \else
    \enit@list{}%
      {\let\enit@type\tw@
       \advance#1\@ne
       \labelwidth\z@
       \enit@align@left
       \let\makelabel\descriptionlabel
       \enit@style@standard
       \enit@preset{#2}{#1}{#4}%
       \enit@calcleft
       \let\enit@svlabel\makelabel
       \def\makelabel##1{%
         \NR@gettitle{##1}%
         \labelsep\z@
         \ifenit@boxdesc
           \enit@svlabel{\enit@align{\enit@format{\enit@descriptionlabel@hook{##1}}}}%
         \else
           \nobreak
           \enit@svlabel{\enit@format{\enit@descriptionlabel@hook{##1}}}%
           \aftergroup\enit@postlabel
         \fi}%
       \enit@before
       \enit@negwidth}%
     \enit@keyfirst
  \fi}

\usepackage{hyperref} 
\AtBeginDocument{\let\descriptionlabel\NRorg@descriptionlabel}
\renewcommand\enit@descriptionlabel@hook[1]{\NR@gettitle{#1}#1}
\begin{document}


\begin{description}
  \item [{Test}\label{Test}] Some text
\end{description}

\nameref{Test}

\end{document}

So to get it working enumitem must add a hook, and hyperref must then use it.

5
  • 1
    Apparently it's not "the best we have" :)
    – Alan Munn
    Jul 17, 2019 at 20:47
  • 1
    @UlrikeFischer Thanks for checking. I get ! Undefined control sequence. <argument> ...el \fi }\enit@before \enit@negwidth l.42 \item [{Test}\label{Test}] Some text The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., `\hobx'), type `I' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.
    – Daniel
    Jul 18, 2019 at 8:24
  • 1
    Is your enumitem version up-to-date? Jul 18, 2019 at 8:26
  • @UlrikeFischer Thanks. Updating my system did the trick! Any idea why the author of enumitem does not fix his package in this way? Or is there a downside?
    – Daniel
    Jul 18, 2019 at 9:09
  • 1
    I wrote to the enumitem maintainer. If he changes enumitem, I can adapt nameref to get it working directly. Jul 18, 2019 at 9:11
2

This is a known issue with enumitem documented in section 12.2 of the documentation. The workaround suggested there is to let \makelabel to \descriptionlabel in the before code of the list, and that indeed seems to work, but as Ulrike points out in the comments, it's not really a complete solution.

\documentclass{article}

\usepackage{enumitem}
\usepackage{hyperref}

\begin{document}

\begin{description}[before=\let\makelabel\descriptionlabel]
  \item [{Test\label{Test}}] Some text
\end{description}

\nameref{Test}

\end{document}
2
  • but this break e.g. the format key, so it is only a work-around. Jul 17, 2019 at 18:42
  • @UlrikeFischer Yes, I think that's clear from the docs. But unless Javier fixes it, I guess it's the best we have?
    – Alan Munn
    Jul 17, 2019 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .