Aim
I want to be able to label and then reference items in description environments created using the enumitem package.
What does not work
The following example modifies the accepted answer at How can I label / reference description items that contain macros by name?.
\documentclass[12pt]{article}
\usepackage[colorlinks=true,linkcolor=red]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{enumitem}
\newlist{describe}{description}{1}
\setlist[describe,1]{%
font=\normalfont\textsf,
itemindent=0pt,
wide,
itemsep=0pt,topsep=2pt,
}
% Redefine Description List Items
% (source: http://tex.stackexchange.com/a/1248/13552)
\makeatletter
\let\orgdescriptionlabel\descriptionlabel
\renewcommand*{\descriptionlabel}[1]{%
\let\orglabel\label
\let\label\@gobble
\phantomsection
\protected@edef\@currentlabel{#1}%
\let\label\orglabel
\orgdescriptionlabel{#1}%
}
\makeatother
\begin{document}
\Large
\section{Good eats}
\begin{describe}
\item [Fruit:] Oranges and apples.
\item [Vegetable:\label{item:veggie}] Kale and potatoes.
\end{describe}
\newpage
Refer to \ref{item:veggie} above on \cpageref{item:veggie}.
\end{document}
Output:
There are three defects with this output:
- The face of the reference is the same sans-serif as the label itself, but I want
normalfontto match the surrounding text. - There is superfluous punctuation (:) in the reference, but I want just the name of the item and not any trailing punctuation. (Note that for different
describeenvironments, the trailing punctuation could be different, e.g., a period instead of a colon.) - There is extra blank space between the reference and the text "above on ..." that follows it.
How can these defects be repaired?
What does work but uses awkward syntax
The following version of the source, based upon the accepted answer at Reference name of description list item in LaTeX, cures all three defects — but at the cost of an awkward syntax within the \item optional argument.
What I find syntactically awkward is that the optional argument to \item includes a new macro \namedlabel that takes two arguments — the label identifier and the item name — and then any punctuation has to go outside and after that 2nd argument.
\documentclass[12pt]{article}
\usepackage[colorlinks=true,linkcolor=red]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{enumitem}
% From
% https://tex.stackexchange.com/questions/1230/reference-name-of-description-list-item-in-latex
\makeatletter
\def\namedlabel#1#2{\begingroup
#2%
\def\@currentlabel{#2}%
\phantomsection\label{#1}\endgroup
}
\makeatother
\newlist{describe}{description}{1}
\setlist[describe,1]{%
font=\normalfont\textsf,
itemindent=0pt,
wide,
itemsep=0pt,topsep=2pt,
}
\crefname{page}{page}{page}
\begin{document}
\Large
\section{Good eats}
\begin{describe}
\item[Fruit:] Oranges and apples.
% Awkward syntax in optional argument to \item below:
\item[\namedlabel{item:veggie}{Vegetable}:] Kale and potatoes.
\end{describe}
%\newpage
Refer to \ref{item:veggie} above on \cpageref{item:veggie}.
\end{document}



:) in the reference text, so you have to tell LaTeX, which part of the description label it should take. Use braces to delimit this part and move the label command in front of it, et voila, you are at the working solution. The main problem with your solution is that you hand everything that\descriptionlabelgets to the label command. This includes all the special formatting that you want to have in thedescribeenvironment but not when referencing it. So just go with the working solution. – gernot Apr 18 '17 at 16:02\namedlabel.) – murray Apr 18 '17 at 16:19