如何定义并链接到标签列表?

如何定义并链接到标签列表?

我想定义一个带标签的列表,并通过超链接按名称引用项目。我的第一个想法是使用描述环境,\label在每个项目中放置一个,然后使用检索值\refname。TeX 无法解析我测试文档中的引用。

\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}

是否有一个软件包可以提供此功能?

更新:

\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}

适用于 \autoref,但不适用于 \cref 或 \refname。

梅威瑟:

\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}

相关内容