# When custom item labels are defined in the enumerate environment, \label does not refer to the right object. Why?

When I use a custom label in the enumerate environment, as follows:

\documentclass{amsart}
\newtheorem{theorem}{Theorem}[section]
\usepackage{enumitem}

\begin{document}

\begin{theorem}Consider the following conditions
\begin{enumerate}
\item[(xy)] Condition 1 \label{a:cond:1}
\item[($\neg$)] Condition 2 \label{a:cond:2}
\item[($\sim$)] Condition 3 \label{a:cond:3}
\end{enumerate}
\end{theorem}
I want \verb|\eqref{a:cond:2}| to output ($\neg$)'' instead of
\eqref{a:cond:2}

\end{document}


The \label commands after each \item are assigning the label to the Theorem instead, so the output is not what I want it to be:

Without the manually modified item labels, the output is as expected:

\documentclass{amsart}
\newtheorem{theorem}{Theorem}[section]
\usepackage{enumitem}

\begin{document}

\begin{theorem}Consider the following conditions
\begin{enumerate}
\item Condition 1 \label{b:cond:1}
\item Condition 2 \label{b:cond:2}
\item Condition 3 \label{b:cond:3}
\end{enumerate}
\end{theorem}
\verb|\eqref{b:cond:2}| works correctly: \eqref{b:cond:2}    \eqref{a:cond:2}

\end{document}


Why is this behaviour occuring and how can I prevent it?

## 1 Answer

\item[(foo)] does not use \refstepcounter{enumi} in an enumerate environment, so \label does use the latest \@currentlabel value, which is always set by \refstepcounter, but in this case it will use the value from a section etc. counter or any counter that has been used with \refstepcounter before.

If \item[foo] shall give a reference 'foo', \@currentlabel must be added by a redefinition of \item[], this is done only locally for the enumerate environment, this way, it does not change the \item command for other list-like environments.

\documentclass{amsart}
\newtheorem{theorem}{Theorem}[section]

\usepackage{xparse}
\usepackage{etoolbox}
\usepackage{enumitem}
\usepackage{letltxmacro}

\makeatletter
\AtBeginDocument{%
\def\strip@@parentheses(#1){#1}
\LetLtxMacro\enumerate@@item\item
\AtBeginEnvironment{enumerate}{%
% Redefine \item only for enumerate
\RenewDocumentCommand{\item}{o}{%
\IfValueTF{#1}{% Check whether \item[...] is used
\enumerate@@item[#1]%
\protected@edef\@currentlabel{\strip@@parentheses#1}% Prepare the label
}{%
\enumerate@@item% Usage without []
}%
}%
}
}
\makeatother

\begin{document}

\begin{theorem}Consider the following conditions
\begin{enumerate}
\item[($xy$)] Condition 1 \label{a:cond:1}
\item[($\neg$)] Condition 2 \label{a:cond:2}
\item[($\sim$)] Condition 3 \label{a:cond:3}
\end{enumerate}
\end{theorem}
I want \verb|\eqref{a:cond:1}| to output ($xy$)'' and it prints: \eqref{a:cond:1}

I want \verb|\eqref{a:cond:2}| to output ($\neg$)'' and it prints: \eqref{a:cond:2}

I want \verb|\eqref{a:cond:3}| to output ($\sim$)'' and it prints: \eqref{a:cond:3}

\end{document}