生成的链接\ref{defn:First Defined Term}
工作正常,但由于我更喜欢使用文本而不是数字,所以认为
\href{defn:First Defined Term}{First Defined Term}
应该可以工作,但事实并非如此:
\documentclass{article}
\usepackage{thmtools}
\usepackage{hyperref}
\usepackage{lipsum}
\declaretheorem[name=Definition]{DefinitionTheorem}
\newenvironment{Definition}[1]{%
\begin{DefinitionTheorem}
\label{defn:#1}
}{%
\end{DefinitionTheorem}
}
\begin{document}
\lipsum[1-7]
\begin{Definition}{First Defined Term}
\lipsum[1]
\end{Definition}
\lipsum[8-10]
\begin{Definition}{Second Defined Term}
\lipsum[1]
\bigskip
This link works great: \ref{defn:First Defined Term}\par\bigskip
But this link does not: \href{defn:First Defined Term}{First Defined Term}
\end{Definition}
\end{document}
答案1
据我所知,该\href
命令仅用于链接到 URL。
改用\hyperref
:
\hyperref[label]{text}
text
\ref{label}
被制成与将被链接的同一位置的链接 。
适合您的示例:
\documentclass{article}
\usepackage{thmtools}
\usepackage{hyperref}
\usepackage{lipsum}
\declaretheorem[name=Definition]{DefinitionTheorem}
\newenvironment{Definition}[1]{%
\begin{DefinitionTheorem}
\label{defn:#1}
}{%
\end{DefinitionTheorem}
}
\begin{document}
\lipsum[1-7]
\begin{Definition}{First Defined Term}
\lipsum[1]
\end{Definition}
\lipsum[8-10]
\begin{Definition}{Second Defined Term}
\lipsum[1]
\bigskip
This link works great: \ref{defn:First Defined Term}\par\bigskip
But this link does not: \hyperref[defn:First Defined Term]{First Defined Term}
\end{Definition}
\end{document}
答案2
您可以使用以下技巧来实现这一点。
\documentclass{article}
\makeatletter
\newcommand*\mylabel[2]{%
\immediate\write\@auxout{\string\newlabel%
\string{#1\string}%
\string{\string{#2\string}%
\string{\thepage\string}\string}}%
}
\makeatother
\makeatletter
\begin{document}
Wow, \mylabel{super}{supercalifragilisticexpialidocious}
this is \ref{super}.
\clearpage
I already told you this is \ref{super} on Page~\pageref{super}.
\end{document}