# How do I define and link to a labelled list?

I want to define a labeled list and refer to the items by name, with hyperlinks. My first thought was to use the description environment, put a \label in each item and retrieve the values with \refname. TeX did not resolve the references in my test document.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{cleveref}
\usepackage{showlabels}
\showlabels{cite}
\showlabels{cref}
\showlabels{crefrange}

\begin{document}
\begin{description}
\item [Open cover] Foo is an open cover for bar. Note that it need
not be a basis for $S$.
\label{mod:cover}

\item [Closed] Foo is closed under finite intersections.
\label{mod:closed}

\item [Continuous] The morphisms of foo are continuous functions in bar.
\label{mod:continuous}

\item [Restriction]
\label{mod:rest}
If $f: A \to B$ is a morphism, $A' \subseteq A$,
$B' \subseteq B$ and $f[A'] \subseteq B'$ then
$f \restriction_{A'} : A' \to B'$ is a morphism.
\label{mod:restriction}

\item [Inclusion] If $A' \subseteq A$ then
the inclusion map $i: A' \hookrightarrow A$ is a morphism.
\label{mod:inclusion}

\item [Restricted sheaf condition]
Informally, consistent morphisms can be glued together. Whenever
\begin{enumerate}
\item $U_\alpha$ and $V_\alpha$, $\alpha \prec A$,
are objects of foo.
\item $f_\alpha: U_\alpha \to V_\alpha$ are morphisms of foo.
\item
$U = \bigcup_{\alpha \prec A} {U_\alpha} \in foo$.
\item
$V = \bigcup_{\alpha \prec A} {V_\alpha} \in bar$.
\item
$f: U \to V$ is a continuous function and
for every $\alpha \prec A$,
$f$ agrees with $f_\alpha$ on $U_\alpha$
\end{enumerate}
then $f$ is a morphism of $foo$.
\label{mod:sheaf}
\end{description}

Test cref\{mod:closed\}: \cref{mod:closed}

Test autoref\{mod:closed\}: \autoref{mod:closed}

Test refname\{mod:closed\}: \refname{mod:closed}
\end{document}


Is there a package that will provide this functionality?

Update:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\makeatletter
\def\namedlabel#1#2{\begingroup
\def\@currentlabel{#2}%
\label{#1}\endgroup
}
\makeatother
\usepackage{cleveref}
\usepackage{showlabels}
\showlabels{cite}
\showlabels{cref}
\showlabels{crefrange}

\begin{document}
\begin{description}
\item [Open cover\namedlabel{mod:cover}{Continuous}] Foo is an open cover for bar. Note that it need
not be a basis for $S$.

\item [Closed\namedlabel{mod:closed}{Closed}] Foo is closed under finite intersections.

\item [Continuous] The morphisms of foo are continuous functions in bar.
\label{mod:continuous}

\item [Restriction]
\label{mod:rest}
If $f: A \to B$ is a morphism, $A' \subseteq A$,
$B' \subseteq B$ and $f[A'] \subseteq B'$ then
$f \restriction_{A'} : A' \to B'$ is a morphism.
\label{mod:restriction}

\item [Inclusion] If $A' \subseteq A$ then
the inclusion map $i: A' \hookrightarrow A$ is a morphism.
\label{mod:inclusion}

\item [Restricted sheaf condition]
Informally, consistent morphisms can be glued together. Whenever
\begin{enumerate}
\item $U_\alpha$ and $V_\alpha$, $\alpha \prec A$,
are objects of foo.
\item $f_\alpha: U_\alpha \to V_\alpha$ are morphisms of foo.
\item
$U = \bigcup_{\alpha \prec A} {U_\alpha} \in foo$.
\item
$V = \bigcup_{\alpha \prec A} {V_\alpha} \in bar$.
\item
$f: U \to V$ is a continuous function and
for every $\alpha \prec A$,
$f$ agrees with $f_\alpha$ on $U_\alpha$
\end{enumerate}
then $f$ is a morphism of $foo$.
\label{mod:sheaf}
\end{description}

Test cref\{mod:closed\}: \cref{mod:closed}

Test autoref\{mod:closed\}: \autoref{mod:closed}

Test refname\{mod:closed\}: \refname{mod:closed}
\end{document}


works for \autoref but not for \cref or \refname.

MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{cleveref}
\usepackage{showlabels}
\showlabels{cite}
\showlabels{cref}
\showlabels{crefrange}
\makeatletter
\def\namedlabel#1#2{\begingroup
\def\@currentlabel{#2}%
\label{#1}\endgroup
}
\makeatother

\begin{document}
\begin{description}
\item [key1\namedlabel{label1}{key1}] Text1
\item [key2\namedlabel{label2}{key2}] Text2
\end{description}

Test cref\{label2\}: \cref{label2}

Test autoref\{label2\}: \autoref{label2}

Test refname\{label2\}: \refname{label2}
\end{document}

• Maybe something like tex.stackexchange.com/questions/1230/… May 13, 2018 at 20:44
• The change suggested in tex.stackexchange.com/questions/1230/… resolves the problem for one of the three tags. May 14, 2018 at 19:09
• Would you please make a MWE (shorter than your piece)? Just retain the necessary structure. Probably that's why anyone offered you a solution
– user134500
May 14, 2018 at 19:56