如何将所有证明自动放置在附录中?

如何将所有证明自动放置在附录中?

我可以自动将所有定理的证明放在附录中吗?通常,证明在 LaTeX 代码中写在定理之后。如果不将证明物理移动到附录,我如何才能自动将它们放在附录中?有包吗?

答案1

这最多提供 1000 个证明,应该足够了。声明定理后,将\fixstatement其放在后面。使用\proofatend...\endproofatend还允许在文档中设置证明(比如主文档)。

\documentclass[a4paper]{article}
\usepackage{etex,etoolbox}
\usepackage{amsthm}

\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.  
\def\fixstatement#1{%
  \AtEndEnvironment{#1}{%
    \xdef\pat@label{\expandafter\expandafter\expandafter
      \@fourthoffour\csname#1\endcsname\space\@currentlabel}}}

% 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
\long\def\proofatend#1\endproofatend{%
  \edef\next{\noexpand\begin{proof}[Proof of \pat@label]}%
  \toks\numexpr\prooftoks+\value{proofcount}\relax=\expandafter{\next#1\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    
\newtheorem{thm}{Theorem}
\newtheorem{lem}[thm]{Lemma}
\fixstatement{thm}
\fixstatement{lem}


\begin{document}
\begin{lem}\label{addition}
$1+1=2$
\end{lem}
\proofatend
It's quite clear.
\endproofatend

\begin{thm}
$1+2=3$
\end{thm}
\proofatend
Obvious from lemma \ref{addition}.
\endproofatend

\section*{Proofs}

\printproofs

\end{document}

每个证明都存储在一个令牌寄存器中,这些寄存器由 卸载\printproofs。较长的证明或大量的证明可能会导致内存问题。


新版本

受 Alfredo Hernández 的评论启发,他要求修复thmtools使用 when 的情况,这里有一个新版本,也有一个附加内容。该命令\fixstatement现在有一个可选参数来声明证明的“前缀”。这可能很重要,因为在某些语言中,人们必须改变构造;在意大利语中,我们应该说“Dimostrazione del Teorema”,但应该说“Dimostrazione della Proposizione”。

\newtheorem我提供了一个同时使用和的示例\declaretheorem;当然,应该坚持使用其中之一。该示例使用了thmtools,但它不是必需的(\declaretheorem当然,如果不加载它,就无法使用)。

第二个变化是environ使用,因此proofatend成为一个环境,具有更连贯的语法。

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

\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.  
\newcommand\fixstatement[2][\proofname\space of]{%
  \ifcsname thmt@original@#2\endcsname
    % the theorem has been declared with \declaretheorem
    \AtEndEnvironment{#2}{%
      \xdef\pat@label{\expandafter\expandafter\expandafter
        \@fourthoffour\csname thmt@original@#2\endcsname\space\@currentlabel}%
      \xdef\pat@proofof{\@nameuse{pat@proofof@#2}}%
    }%
  \else
    % the theorem has been declared with \newtheorem
    \AtEndEnvironment{#2}{%
      \xdef\pat@label{\expandafter\expandafter\expandafter
        \@fourthoffour\csname #1\endcsname\space\@currentlabel}%
      \xdef\pat@proofof{\@nameuse{pat@proofof@#2}}%
    }%
  \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}{%
  \edef\next{%
    \noexpand\begin{proof}[\pat@proofof\space\pat@label]%
    \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}\label{addition}
$1+1=2$
\end{lem}
\begin{proofatend}
It's quite clear.
\end{proofatend}

\begin{thm}
$1+2=3$
\end{thm}
\begin{proofatend}
Obvious from lemma \ref{addition}.
\end{proofatend}

\section*{Proofs}

\printproofs

\end{document}

在此处输入图片描述

图中我们有 0.1 和 0.2,因为没有\section发出任何命令。当然,这在正常文档中不会发生。

答案2

我最近了解到以下软件包,由皮埃尔·塞内拉特,这似乎正是您想要的:

防伪https://ctan.org/pkg/apxproof

该软件包使撰写将证明和其他材料推迟到附录的文章变得更加容易。
附录材料与它自然补充的正文一起以 LaTeX 代码编写,并且会自动推迟。
该软件包可以自动将证明发送到附录,可以在附录中重复正文中所述的定理环境,可以根据正文的分段自动对附录进行分段,并支持为附录材料提供单独的参考书目。

答案3

tcolorbox提供一些recording命令,允许保存盒子内容以便稍后恢复。

savelowerto将把文本保存到tcblower可以用其读取的辅助文件中\tcbinputrecords

命令\tcbstartrecording\tcbstoprecording定义何时savelowerto应用。

有关这些命令的更多信息,请参见recording摘自文档部分tcolorbox

下面的代码显示了一个小例子:

\documentclass{article}

\usepackage{lipsum}
\usepackage[most]{tcolorbox}

\NewTColorBox[auto counter, number within=section]{theorem}{+O{}}{ %
enhanced,
colframe=green!20!black,
colback=yellow!10!white,
coltitle=green!40!black,
fonttitle=\bfseries,
title={Theorem~\thetcbcounter:},
label={theorem@\thetcbcounter},
attach title to upper=\quad,
after upper={\par\hfill\textcolor{green!40!black} %
{\itshape Proof on page~\pageref{proof@\thetcbcounter}}},
lowerbox=ignored,
savelowerto=theorems/theorem-\thetcbcounter.tex,
record={\string\proof{\thetcbcounter}{theorems/theorem-\thetcbcounter.tex}},
#1
}

\NewTotalTColorBox{\proof}{mm}{ %
enhanced,
colframe=red!20!black,colback=yellow!10!white,
coltitle=red!40!black,
fonttitle=\bfseries,
title={Proof of Theorem~\ref{theorem@#1} on page~\pageref{theorem@#1}:},
phantomlabel={proof@#1},
attach title to upper=\par,
}{\input{#2}}

\tcbset{no proof/.style={no recording,after upper=}}

\begin{document}
\section{Some theorems}

\tcbstartrecording

\lipsum[2]
\begin{theorem}
First theorem:
1+2=3
\tcblower
Proof is obvious
\end{theorem}


\begin{theorem}[no proof]
This theorem has no proof to be printed
\end{theorem}


\begin{theorem}
Another theorem with proof
\tcblower
This is the proof of third theorem
\end{theorem}

\lipsum[1-3]
\tcbstoprecording

\section{Some theorems can be prooved}

\tcbinputrecords

\end{document}

在此处输入图片描述

虽然前面的例子显示了装饰框,但blankest样式选项会抑制文本周围的所有颜色、边框和边距,甚至 tcolorbox-theorems 看起来也像常规定理,如在单独的文件中重述定理

答案4

我在这里写了一个答案最终证明在最后/附录中:不同章节,参考证明/定理、重述和同步我提供了一个超级容易使用的迷你库,以便将定理放在不同的地方,将它们与引理混合,引用它们,重述它们,在附录和主要部分中复制证明(适用于 synctex),在附录中添加注释,在定理和证明之间建立链接......

为了避免答案重复,这里就不贴代码了,直接贴图吧: 在此处输入图片描述

相关内容