# Enumitem with hyperref's \nameref, in complex environments

by Coby Viner   Last Updated October 09, 2019 23:23 PM - source

I am trying to get \nameref to work properly with enumitem. To do so, I am using the preamble code provided in the existing answer on this topic.

I am then wrapping the document code from that answer, within a custom command, as shown below (and partly adapted from another answer):

\newcommand{\labelleditem}[1]{%
\stepcounter{enumi}%
\item[{\theenumi{}}\label{#1}]%
}


I want to make use of the description environment, with the optional arguments of an enumerate environment, as follows:

\begin{description}[label={($\text{A}_{\arabic*}$)}, series=name, resume=name]
\labelleditem{Broken} XXX
\item XXX
\end{description}


This does not work, presumably in part due to the description environment not fully-implementing or making accessible the enumitem optional arguments.

How might I be able to get this to work, similar to the existing answer on this topic, but with my additional specifications, shown above?

Alternatively, how can I get \nameref to work via a more general or direct patch to enumitem?

MWE:

\documentclass{article}

\usepackage{enumitem}

\makeatletter
\newcommand\[email protected]@hook[1]{}
\def\[email protected]@i#1#2#3#4{%
\ifnum#1>#3\relax
\[email protected]
\else
\[email protected]{}%
{\let\[email protected]\[email protected]
\labelwidth\[email protected]
\[email protected]@left
\let\makelabel\descriptionlabel
\[email protected]@standard
\[email protected]{#2}{#1}{#4}%
\[email protected]
\let\[email protected]\makelabel
\def\makelabel##1{%
\[email protected]{##1}%
\labelsep\[email protected]
\[email protected]
\[email protected]{\[email protected]{\[email protected]{\[email protected]@hook{##1}}}}%
\else
\nobreak
\[email protected]{\[email protected]{\[email protected]@hook{##1}}}%
\aftergroup\[email protected]
\fi}%
\[email protected]
\[email protected]%
}%
\[email protected]
\fi}

\usepackage{hyperref}

\AtBeginDocument{\let\descriptionlabel\[email protected]}
\renewcommand\[email protected]@hook[1]{\[email protected]{#1}#1}

\newcommand{\labelleditem}[1]{%
%\label{#1}%
\stepcounter{enumi}%
\item[{\theenumi{}}\label{#1}]%
%
}
% -------------------------------------

\begin{document}

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

\begin{description}[label={($\text{A}_{\arabic*}$)}, series=name, resume=name]
\labelleditem{Broken} XXX
\item XXX
\end{description}

\nameref{Test}

\nameref{Broken}

\end{document}


The above produces:

It also outputs the following error:

Missing control sequence inserted.
<inserted text>
\inaccessible
l.57 ...}_{\arabic*}\$)}, series=name, resume=name]


I also provide this MWE on Overleaf.

Tags :