(Repost from Stack Overflow)
I'd like to refer to a description list item by name instead of number. To that effect, I've added labels to each item, but when referencing them I only get the name of the section, not of the list item. How can I change it to show a custom label for each item?
\section{Definitions}
\begin{description}
\item [Vehicle\label{itm:vehicle}] Something
\item [Bus\label{itm:bus}] A type of \nameref{itm:vehicle}
\item [Car\label{itm:car}] A type of \nameref{itm:vehicle} smaller than a \nameref{itm:bus}
\end{description}
The result is something like this:
1 Definitions
Vehicle Something
Bus A type of Definitions
Car A type of Definitions smaller than a Definitions
I'd like to have the following:
1 Definitions
Vehicle Something
Bus A type of Vehicle
Car A type of Vehicle smaller than a Bus
An alternative solution would be to use subsections and display them as a definition list. Anyone know how to do it?
The best answer on Stack Overflow referenced a \makeatletter hack:
\makeatletter
\def\namedlabel#1#2{\begingroup
\def\@currentlabel{#2}%
\label{#1}\endgroup
}
\makeatother
...
\section{Definitions}
\begin{description}
\item [Vehicle\namedlabel{itm:vehicle}{Vehicle}] Something
\item [Bus\namedlabel{itm:bus}{Bus}] A type of \ref{itm:vehicle}
\item [Car\namedlabel{itm:car}{Car}] A type of \ref{itm:vehicle} smaller than a \ref{itm:bus}
\end{description}
It works, with the caveat that the links lead back to the section header, not to the list item. It would be nice to use something native which doesn't break \ref
.