将证明放在附录中,并附上定理和证明之间的链接

将证明放在附录中,并附上定理和证明之间的链接

我希望能够在附录中添加一些我的文档的证明。我喜欢给出的“新版本”解决方案这里,但除此之外我还想:

  1. 定理下方的文字写着类似“请在附录中找到该定理的证明”的内容。
  2. 将此文本中的链接添加到证明中
  3. 添加从证明标题到定理的另一个链接
  4. 如果可能的话,回想一下证明上面的定理

例如,在伪生成代码中它看起来像:

Theorem 1.1
  \label{th1.1}
  1 = 1
Please find the \hyperlink{th1.1}{proof of this theorem} in appendix.
[... lot's of stuff ...]

Proofs.
Theorem 1.1
  1 = 1
\hypertarget{th1.1}
Proof of \autoref{th1.1}
  Trivial.

我试图自己改变上述答案的代码,但是我不太熟悉 tex 语法,并且我被卡在第 3 点,而链接指向无处可去(我怀疑有错误expandafter,但我不知道如何调试我的代码)。

感谢您的帮助 !

答案1

我找到了第一个解决方案,它似乎对点 1、2、3 有效,但不适用于点 4:我不知道如何改变定理的环境(\begin{theorem}必须在编辑中进行变换\begin{restatable}[]{theorem}{}:似乎添加一个选项restate=foo就足够了,但我不知道如何添加这样的选项...我试过设置\xdef\pat@restate{foo}但它不起作用...有什么想法吗?)。

\documentclass[a4paper]{article}
\usepackage{etex,etoolbox}
\usepackage{amsthm,amssymb}
\usepackage{thmtools}
\usepackage{environ}
\usepackage[colorlinks]{hyperref}
\usepackage{blindtext}

\makeatletter
\providecommand{\@fourthoffour}[4]{#4}
% We define an addition for the theorem-like environments; when
% \newtheorem{thm}{Theorem} is declared, the macro \thm expands
% to {...}{...}{...}{Theorem} and with \@fourthoffour we access
% to it; then we make available \@currentlabel (the theorem number)
% also outside the environment.
\newcounter{counttheorems}

\newcommand\fixstatement[2][\proofname\space of]{%
  \ifcsname thmt@original@#2\endcsname
    % the theorem has been declared with \declaretheorem
    \AtEndEnvironment{#2}{%
      \xdef\pat@uniqlabel{\thecounttheorems}%
      \xdef\pat@label{\expandafter\expandafter\expandafter
        \@fourthoffour\csname thmt@original@#2\endcsname\space\@currentlabel}%
      \xdef\pat@proofof{\@nameuse{pat@proofof@#2}}%
      \addtocounter{counttheorems}{1}
      \expandafter\label{thm_uniq:\pat@uniqlabel}
    }%
  \else
    % the theorem has been declared with \newtheorem
    \AtEndEnvironment{#2}{%
      \xdef\pat@uniqlabel{\thecounttheorems}%
      \xdef\pat@label{\expandafter\expandafter\expandafter
        \@fourthoffour\csname #1\endcsname\space\@currentlabel}%
      \xdef\pat@proofof{\@nameuse{pat@proofof@#2}}%
      \addtocounter{counttheorems}{1}
      \expandafter\label{thm_uniq:\pat@uniqlabel}
    }%
  \fi
  \@namedef{pat@proofof@#2}{#1}%
}

% We allocate a block of 1000 token registers; in this way \prooftoks
% is 1000 and we can access the following registers of the block by
% \prooftoks+n (0<n<1000); we'll use a dedicated counter for it
% that is stepped at every proof
\globtoksblk\prooftoks{1000}
\newcounter{proofcount}

% We gather the contents of the proof as argument to \proofatend
% and then we store
% "\begin{proof}[Proof of <theoremname> <theoremnumber>]#1\end{proof}"
% in the next token register of the allocated block
\NewEnviron{proofatend}{%
  You can find \hyperlink{proofatend:\pat@uniqlabel}{the proof} at the end of the paper.
  % [\textbf{thm_fix:\pat@uniqlabel}]\hyperlink{thm_fix:\pat@uniqlabel}{Ahah}\\
  \edef\next{%
    % \noexpand\begin{proof}[\pat@proofof\space\pat@label]%
    \noexpand\begin{proof}[\pat@proofof\space\noexpand\autoref{thm_uniq:\pat@uniqlabel}]%
      \noexpand\hypertarget{proofatend:\pat@uniqlabel}
      \unexpanded\expandafter{\BODY}}%
  \global\toks\numexpr\prooftoks+\value{proofcount}\relax=\expandafter{\next\end{proof}}
  \stepcounter{proofcount}}

% \printproofs simply loops over the used token registers of the
% block, freeing their contents
\def\printproofs{%
  \count@=\z@
  \loop
    \the\toks\numexpr\prooftoks+\count@\relax
    \ifnum\count@<\value{proofcount}%
    \advance\count@\@ne
  \repeat}
\makeatother

% Here starts the example, with two theorem declarations
\declaretheorem[style=plain,name=Theorem,qed=$\square$,numberwithin=section]{thm}
%\declaretheorem[style=plain,name=Lemma,qed=$\square$,numberlike=thm]{lem}
%\newtheorem{thm}{Theorem}
\newtheorem{lem}[thm]{Lemma}
\fixstatement{thm}
\fixstatement[Demonstration of]{lem}


\begin{document}
\begin{lem}
$1+1=2$
\end{lem}
\begin{proofatend}
It's quite clear. \Blindtext
\end{proofatend}
\newpage
\begin{thm}
$1+2=3$
\end{thm}
\begin{proofatend}
Obvious from lemma. \Blindtext
\end{proofatend}
\newpage
\section*{Proofs}

\printproofs

\end{document}

相关内容