我有定理,例如,下面的引理,其证明在附录中提供。如何使引理可点击并指向附录中的可重述部分(或证明)?
插图如下。
这是上图的最小代码。
\documentclass{article}
\usepackage{amsmath, amsthm, thm-restate}
\newtheorem{lemma}{Lemma}
\begin{document}
\begin{restatable}[Ni]{lemma}{mylemma}\label{thm:mylemma}
Given us be the knight, we say Ni.
\end{restatable}
\appendix
\section{Appendix: proofs}
\mylemma*
\begin{proof}
It is true, Ni!
\end{proof}
\end{document}
答案1
这里有一个选项,使用 thmtools 的内部\ifthmt@thisistheone
来测试我们是在原始定理还是重述定理中。这个想法是定义一个定理风格,灵感来自 egreg 的回答这里,其中标题检查定理是否重述,然后进行适当链接。使用\NewLinkedTheorem
方法与 完全相同\newtheorem
。
\documentclass{article}
\usepackage{amsthm,thmtools,kantlipsum}
\usepackage[colorlinks]{hyperref}
\makeatletter
\newtheoremstyle{linkedrestate}
{}% Space above, empty = `usual value'
{}% Space below
{\itshape}% Body font
{}% Indent amount (empty = no indent, \parindent = para indent)
{\bfseries}% Thm head font
{.}% Punctuation after thm head
{ }% Space after thm head: " " = normal interword space;
% \newline = linebreak
{%
\ifthmt@thisistheone
\hyperlink{restated:\thisthm}{\thmname{#1} \thmnumber{#2}\unskip}%
\thmnote{ (#3)}%
\hypertarget{orig:\thisthm}{}%
\else
\hyperlink{orig:\thisthm}{\thmname{#1} \thmnumber{#2}\unskip}%
\thmnote{ (#3)}%
\hypertarget{restated:\thisthm}{}%
\fi
}% Thm head spec
\NewDocumentCommand{\NewLinkedTheorem}{s m o m o}{
\let\current@thmstyle\thmt@outerstyle % store current theorem style
\IfBooleanTF{#1}{
\newtheorem*{#2}{#4}
\theoremstyle{linkedrestate}
\newtheorem*{linked-#2}{#4}
\ExpandArgs{e}\theoremstyle{\current@thmstyle} % reset theorem style
}{
\IfNoValueTF{#3}{
\IfNoValueTF{#5}{
\newtheorem{#2}{#4}
}{
\newtheorem{#2}{#4}[#5]
}
}{
\newtheorem{#2}[#3]{#4}
}
\theoremstyle{linkedrestate}
\newtheorem{linked-#2}[#2]{#4}
\ExpandArgs{e}\theoremstyle{\current@thmstyle} % reset theorem style
}
}
\makeatother
\NewDocumentEnvironment{linkrestatable}{O{} m m +b}{%
\def\thisthm{#3}%
\begin{restatable}[#1]{linked-#2}{#3}
#4
\end{restatable}
\AddToHook{cmd/#3/before}{\def\thisthm{#3}}%
}{}
\NewLinkedTheorem{theorem}{Theorem}[section]
\NewLinkedTheorem*{KL}{Klein's Lemma}
\begin{document}
\section{Theorems}
\begin{linkrestatable}{theorem}{mytag}
\kant[2][1]
\end{linkrestatable}
\begin{theorem}
\kant[3][1]
\end{theorem}
\mytag*
\begin{linkrestatable}{KL}{anothertag}
\kant[4][1]
\end{linkrestatable}
\begin{KL}
\kant[5][1]
\end{KL}
\anothertag*
\end{document}