我有一本较长的书,memoir
使用了许多由 定义的定理ntheorem
。我想检查一下我是否thm-restate
在后面的章节中正确地重述了所有定理(在 的帮助下完成)。
\documentclass{memoir}
\usepackage{ntheorem}
\usepackage{thm-restate}
\newtheorem{theorem}{Theorem}
\begin{document}
\chapter{One}
\begin{restatable}{theorem}{thone}
Blah
\end{restatable}
\begin{restatable}{theorem}{thtwo}
Blah
\end{restatable}
%Does not count within the same chapter:
\thone*
\thtwo*
\chapter{Two}
\thone*
%thtwo* is missing here!
\end{document}
打印完整的定理列表并没有太大帮助:无论如何我都需要检查每个定理。我需要的是可重述但在后续章节中从未重述过的定理列表。这可能吗?
或者,如果某些东西被声明为可重述,但从未被重述,我可能会收到错误吗?
答案1
该解决方案为restatable
环境提供了一个补丁,创建了两个列表,包含 1)所有可重述定理(\listofrestatable
)和 2)所有实际重述定理(\listofrestatated
) - 通过以下步骤完成。
设#2
和#3
为环境的宏输入restatable
。然后:
将当前定理名称及其定理环境名称附加到令牌寄存器。
\g@addto@toks\listofrestatable{\process@comma#3 (#2)}
其中,
\g@addto@toks
是一个辅助宏,用于将标记附加到标记寄存器,并且\process@comma
是一个辅助宏,用于确保列表中的逗号被正确处理。定义一个专用的
\add@restated@<restatable thm>
宏,该宏在第一次使用后自行禁用,以确保\listofrestated
不包含重复的条目。\global\@namedef{add@restated@#3}{% \g@addto@toks\listofrestatated{#3; }% \global\cslet{add@restated@#3}{\relax}% }
\<restatable thm>
将最后一个宏添加到(在您的示例中)的定义前面\aTheorem
:\csgpreto{#3}{\@nameuse{add@restated@#3}}
。最后创建一个调试章节,如下所示,以检查列表。
\chapter{Debugging} \typeout{restatable: \the\listofrestatable} List of restatable theorems: \the\listofrestatable \vspace{1pc} \typeout{restatated: \the\listofrestatable} \noindent List of restatated theorems: \the\listofrestatated
请注意,在我的示例中(完整代码如下),我为了测试目的创建了另外两个可重述定理“bTheorem”和“cTheorem”。
此外,最后,您可以使用所有这些来检查未重述的定理,方法是循环遍历所有可重述的定理,并检查相应的定理是否\<restatable thm>
被重述,\relax
这意味着它被重述(参见上文):
\def\notrestated{}
\def\checknotrestated{%
\@for\@rthm:=\the\@toks@restatable\do{%
\ifx\@rthm\@empty\else
\expandafter\ifx\csname add@restated@\@rthm\endcsname\relax\else
\xdef\notrestated{\notrestated\@rthm; }\fi
\fi
}
\ifx\notrestated\empty\else
\par\vspace{1pc}\par\noindent
Warning! -- There were theorems that have not been restated: \notrestated
\@latex@warning{There were theorems that have not been restated: \notrestated}%
\fi
}
这需要事先做一些准备,即\@toks@restatable
仅包含可重述定理名称的寄存器:
...
\makeatletter
\long\def\g@addto@toks#1#2{\global#1\expandafter{\the#1#2}}
\newtoks\@toks@restatable
\newtoks\listofrestatable
...
\renewenvironment{restatable}[3][]{%
\g@addto@toks\@toks@restatable{#3,}%
...
该\checknotrestated
宏最终可以在调试章节中使用。
\chapter{Debugging}
\typeout{restatable: \the\listofrestatable}
List of restatable theorems: \the\listofrestatable
...
\checknotrestated
这将添加预期的输出:
警告!——有一些定理尚未重述:b定理;c定理;
完整代码
\documentclass{memoir}
\usepackage{ntheorem}
\newtheorem{theorem}{Theorem}
\usepackage{thm-restate}
\usepackage{etoolbox}
\makeatletter
\long\def\g@addto@toks#1#2{\global#1\expandafter{\the#1#2}}
\newtoks\@toks@restatable
\newtoks\listofrestatable
\newtoks\listofrestatated
\let\tre@restatable\restatable
\let\tre@endrestatable\endrestatable
\renewenvironment{restatable}[3][]{%
\g@addto@toks\@toks@restatable{#3,}%
\g@addto@toks\listofrestatable{\process@comma#3 (#2)}%
\global\@namedef{add@restated@#3}{%
\g@addto@toks\listofrestatated{#3; }%
\global\cslet{add@restated@#3}{\relax}%
}
\tre@restatable[#1]{#2}{#3}%
\csgpreto{#3}{\@nameuse{add@restated@#3}}%
}{\tre@endrestatable}
\def\process@comma{\def\process@comma{,\space}}
\def\notrestated{}
\def\checknotrestated{%
\@for\@rthm:=\the\@toks@restatable\do{%
\ifx\@rthm\@empty\else
\expandafter\ifx\csname add@restated@\@rthm\endcsname\relax\else
\xdef\notrestated{\notrestated\@rthm; }\fi
\fi
}
\ifx\notrestated\empty\else
\par\vspace{1pc}\par\noindent
Warning! -- There were theorems that have not been restated: \notrestated
\@latex@warning{There were theorems that have not been restated: \notrestated}%
\fi
}
\makeatletter
\begin{document}
\chapter{One}
\begin{restatable}{theorem}{aTheorem}
some text
\end{restatable}
\begin{restatable}{theorem}{bTheorem}
foo
\end{restatable}
\begin{restatable}{theorem}{cTheorem}
bar
\end{restatable}
\chapter{Later}
\aTheorem*
%\bTheorem*
%\cTheorem*
\chapter{Debugging}
\typeout{restatable: \the\listofrestatable}
List of restatable theorems: \the\listofrestatable
\vspace{1pc}
\typeout{restatated: \the\listofrestatable}
\noindent
List of restatated theorems: \the\listofrestatated
\checknotrestated
\end{document}