jbezos / enumitem

Customize enumerate, itemize and description
MIT License
45 stars 5 forks source link

nameref and enumitem #19

Open u-fischer opened 5 years ago

u-fischer commented 5 years ago

on tex.sx a question about the incompability of enumitem with nameref was asked.

I think one could resolve the problem if enumitem had a hook in the right places that nameref could detect and use instead of redefining \descriptionlabel.

https://tex.stackexchange.com/a/500401/2388

jbezos commented 5 years ago

I'll have a look at it. Here is the proposed code:

\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}