在陈述定理之前先重述它

在陈述定理之前先重述它

我计划将扩展摘要作为论文的前言(我使用 cleanthesis),其中包含主要结果的陈述(定理、命题等)。

我希望它们出现在扩展摘要中,使用相同的编号(章节.部分.环境),并链接到论文中的原始陈述。也就是说,我想要一份序言中陈述的精确副本,但不包括与原始陈述的链接。

经过一番研究,我发现 thmtools 的 thm-restate 包提供了此功能。问题是我需要将原始语句保留在主论文中;也就是说,我需要调用出现在原始语句“之前”,然后我得到了一个编译错误:“!未定义的控制序列。”

我该如何修复此问题?

(我不知道这是否相关,但该文档被分成不同的文件:本质上,第一个文件对应于序言,然后每个章节一个文件。)

答案1

我认为这是最简单的方法:语句在第一次出现时就被输入。

\documentclass{book}

\newtheorem{theorem}{Theorem}[chapter]

\ExplSyntaxOn

\NewDocumentEnvironment{restatethis}{m+b}
 {% #1 (mandatory): a label
  \group_begin:
  \cs_gset:cpn {restatethis@#1}{ #2 }
  \renewcommand{\thetheorem}{\ref{#1}}
  \begin{theorem}#2\end{theorem}
  \addtocounter{theorem}{-1}
  \group_end:
}{}

\NewDocumentCommand{\restate}{m}
 {
  \begin{theorem}\label{#1}\use:c {restatethis@#1}\end{theorem}
 }

\ExplSyntaxOff

\begin{document}

\frontmatter

\chapter{Introduction}

This is the introduction, where we have a theorem

\begin{restatethis}{main}
This is the main theorem in the thesis.
\end{restatethis}

\mainmatter

\chapter{Main result}

Here we prove our main theorem.

\restate{main}

\end{document}

定理的陈述位于主体中的替代解决方案。

\documentclass{book}

\newtheorem{theorem}{Theorem}[chapter]

\ExplSyntaxOn

\NewDocumentEnvironment{restatethis}{m+b}
{% #1 (mandatory): a label
    \AddToHookNext{para/begin}{
        \iow_shipout:cn { @auxout } {
            \RESTATETHEOREM{#1}{#2}
        }
    }
    \begin{theorem}\label{#1}#2\end{theorem}
}{}

\NewDocumentCommand{\RESTATETHEOREM}{mm}
 {%
  \cs_gset:cpn {RESTATETHIS@#1} {#2}%
 }
\NewDocumentCommand{\restate}{m}
 {
  \group_begin: 
  \renewcommand{\thetheorem}{\ref{#1}}
  \begin{theorem} \use:c {RESTATETHIS@#1} \end{theorem}
  \addtocounter{theorem}{-1}
  \group_end:
}

\ExplSyntaxOff

\begin{document}

\frontmatter

\chapter{Introduction}

This is the introduction, where we have a theorem

\restate{main}

\mainmatter

\chapter{Main result}

Here we prove our main theorem.

\begin{restatethis}{main}
This is the main theorem in the thesis.
\end{restatethis}

\end{document}

注:请参阅带有的原始代码的编辑历史\NewEnviron

感谢 daleif 和 yo 提出的变更建议。

答案2

我一直在使用 @egreg 代码的稍作修改的版本,所以我想把它放在这里。它的设置与环境非常相似mathtoolsrestatable它可以与 amsthm、ntheorem 和 mathtools(当前版本)一起正常工作。

令人烦恼的是,如果您使用标准定理包将两个定理环境一起编号,则在编号推论时\newtheorem会定义\thecorollary但使用,因此重新定义根本不会改变编号。在这种情况下,我必须查看定义内部才能找出哪个宏拥有推论编号。包修复了这个缺陷,因此如果已加载,则只需重新定义即可。\thetheorem\thecorollary\corollarymathtools\thecorollary

\documentclass{article}
\usepackage{environ}


\newtheorem{thm}{Theorem}[section]
\newtheorem{cor}[thm]{Corollary}
\makeatletter
\long\def\@secondofthree#1#2#3{#2}
\long\def\@thirdoffour#1#2#3#4{#3}

% #1 -- theorem type
% #2 -- name
\NewEnviron{restatethis}[2]{%
  \begin{#1}%
      \BODY
      % Do the write inside the body of the theorem environment because if I do it afterwards it messes
      % up the spacing for some strange reason...
      \protected@write\@auxout{}{%
        \string\@restatetheorem{#1}{#2}{\csname the#1\endcsname}{\detokenize\expandafter{\BODY}}%
      }%
  \end{#1}%
}

% Figure out which macro to redefine to change the numbering.
% Easy if thmtools is loaded, otherwise we have to extract the name from some macro.
% This will break if some jerk loads thmtools and then ntheorem.
\@ifpackageloaded{thmtools}{%
    % just use the name of the environment
    \def\restatethm@getthmcountercsname#1{\def\thethmcsname{#1}}%
}{%
    \@ifpackageloaded{ntheorem}{%
        % extract the right macro from \mkheader@thmtype -> ???? \@thm{environmentname}{numberwithname}{thmname}
        \def\restatethm@getthmcountercsname#1{%
            \def\thethmcsname{\expandafter\expandafter\expandafter\restatethm@ntheorem@getthmcountercsname@helper\csname mkheader@#1\endcsname}}%
        \def\restatethm@ntheorem@getthmcountercsname@helper#1\@thm#2#3#4{#3}
    }{%
        \@ifpackageloaded{amsthm}{%
            % extract the right macro from \thmtype -> \@thm{????}{numberwithname}{thmname} (it's the third thing)
            \def\restatethm@getthmcountercsname#1{\edef\thethmcsname{\expandafter\expandafter\expandafter\@thirdoffour\csname#1\endcsname}}%
        }{%
            % extract the right macro from \thmtype -> \@thm{numberwithname}{thmname} (it's the second thing)
            \def\restatethm@getthmcountercsname#1{\edef\thethmcsname{\expandafter\expandafter\expandafter\@secondofthree\csname#1\endcsname}}%
        }%
    }%
}

% #1 -- environment type
% #2 -- name for restating
% #3 -- number
% #4 -- content
\newcommand{\@restatetheorem}[4]{%
  \expandafter\gdef\csname restatethis@#2\endcsname{%
    \begingroup
    % First we have to set the numerical label to the right value.
    \restatethm@getthmcountercsname{#1}
    \expandafter\def\csname the\thethmcsname\endcsname{#3}%
    % Print the theorem
    \begin{#1}#4\end{#1}%
    \endgroup
  }%
}
\newcommand{\restate}[1]{\csname restatethis@#1\endcsname} % Just use the stored macro
\makeatother

\begin{document}


\section{Introduction}

This is the introduction, where we restate some theorems:

\restate{main}

\restate{acorollary}



\section{Main result}

Here we prove our main theorem.
\begin{restatethis}{thm}{main}
This is the main theorem in the thesis.
\end{restatethis}
\begin{restatethis}{cor}{acorollary}
This is a corollary.
\end{restatethis}


\end{document} 

相关内容