2

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[colorlinks,hidelinks]{hyperref}
\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[colorlinks,hidelinks]{hyperref}
\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[colorlinks,hidelinks]{hyperref}
\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.