结论
如何将所有肮脏但必要的“引理/证明”扔进附录,并在正文中重述它们?
我尝试了几次,但似乎我的要求很奇怪......所以在提问之前我想解释一下。
我正在写一篇数学论文。我认为写数学论证就像写代码:语句是“函数”,证明是肉体。为了完整起见,我想包含尽可能多的证明。但是,由于论证的结构不是线性的,这样做必然会大大降低可读性。因此,我想将脏东西隐藏在附录中,并在正文中引用 def/thm/proof。
理想情况下,伪 tex 代码应如下所示。
Section 1
#call{main-theorem}
% nothing input here.
#endcall
.
.
Section 10
.
.
Appendix
#theorem[callable]{main-theorem}
2-1=1.
#end-theorem
为了实现这一点,@Bernard 在 [1] 中为我指出了这thmtools
一点。为了实现我真正想要的,我遇到了一个错误,但由于这不是那里的主要话题,所以我在这里提出了一个新问题。
最小示例
下面是一个(几乎)可以工作的最小示例。
\documentclass{article}
\usepackage{thmtools, thm-restate}
\declaretheorem{theorem}
\begin{document}
%\firsteuclid*
%%% Uncommenting the above causes an error:
%%% > ! Undefined control sequence.
%%% > l.7 \firsteuclid
\begin{restatable}[Euclid]{theorem}{firsteuclid}
\label{thm:euclid}
$$1+1 = 2.$$
\end{restatable}
\firsteuclid* % This, however, works fine.
\end{document}
它编译正确。然而,我希望我可以\firsteuclid*
在声明之前先调用它。尝试失败。您可以通过取消注释注释行来复制该操作。
当然,一种解决方法是接受它的限制,并像 [2] 中那样声明语句。但我也希望肮脏的代码都可以在源文件中组合在一起。当我想在下一篇论文中使用它们时,这将使我的生活变得更加轻松。同样,类比仍然适用:你编写了好的代码,并一次又一次地使用它们。
问题
如何将所有肮脏但必要的“代码”扔进附录,并在正文中重述它们?
参考
[1]引用同一篇文献吗?
[2]在陈述之前使用可重述的
[3] 同样相关..我的另一次尝试延迟呈现某个部分
答案1
这是一个概念证明。
\documentclass{article}
\usepackage{amsthm}
\ExplSyntaxOn
\NewDocumentCommand{\theoremstatement}{m m}
{% #1 = label, #2 = theorem type
\use:e
{
\exp_not:N \begin{#2}
\prop_item:Nn \g_student_theorems_statements_prop { #1 }
\exp_not:N \end{#2}
}
\prop_gput:Nnx \g_student_theorems_numbers_prop { #1 } { \thethm }
}
\NewDocumentEnvironment{delayedtheorem}{m m +b}
% #1 = label, #2 = theorem type, #3 = theorem statement
{
\cs_set:Npx \thethm { \prop_item:Nn \g_student_theorems_numbers_prop { #1 } }
\begin{#2}#3\end{#2}
\iow_now:Nn \g_student_theorems_statements_iow
{
\studentpropgput { g_student_theorems_statements_prop } { #1 } { #3 }
}
}{}
\cs_new_eq:NN \studentpropgput \prop_gput:cnn
\iow_new:N \g_student_theorems_statements_iow
\prop_new:N \g_student_theorems_statements_prop
\prop_new:N \g_student_theorems_numbers_prop
\AtBeginDocument
{
\file_if_exist_input:n { \c_sys_jobname_str.thm }
\iow_open:Nn \g_student_theorems_statements_iow { \c_sys_jobname_str.thm }
}
\ExplSyntaxOff
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\begin{document}
\section{First}
\begin{thm}
This is a normal theorem.
\end{thm}
\begin{proof}
Which has a proof.
\end{proof}
\theoremstatement{A}{thm}
\section{Second}
\theoremstatement{B}{lem}
\appendix
\section{Statements and proofs}
\begin{delayedtheorem}{A}{thm}
This is a theorem whose proof is in the appendix.
\end{delayedtheorem}
\begin{proof}
And its proof.
\end{proof}
\begin{delayedtheorem}{B}{lem}[With name]
A boring lemma.
\end{delayedtheorem}
\begin{proof}
Even more boring proof.
\end{proof}
\end{document}
thmtools
上述代码无法正常工作thmtools
,但可以进行调整。
\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\ExplSyntaxOn
\NewDocumentCommand{\theoremstatement}{m m}
{% #1 = label, #2 = theorem type
\use:e
{
\exp_not:N \begin{#2}
\prop_item:Nn \g_student_theorems_statements_prop { #1 }
\exp_not:N \end{#2}
}
\prop_gput:Nnx \g_student_theorems_numbers_prop { #1 } { \use:c {the#2} }
}
\NewDocumentEnvironment{delayedtheorem}{m m +b}
% #1 = label, #2 = theorem type, #3 = theorem statement
{
\cs_set:cpx {the#2} { \prop_item:Nn \g_student_theorems_numbers_prop { #1 } }
\begin{#2}#3\end{#2}
\iow_now:Nn \g_student_theorems_statements_iow
{
\studentpropgput { g_student_theorems_statements_prop } { #1 } { #3 }
}
}{}
\cs_new_eq:NN \studentpropgput \prop_gput:cnn
\iow_new:N \g_student_theorems_statements_iow
\prop_new:N \g_student_theorems_statements_prop
\prop_new:N \g_student_theorems_numbers_prop
\AtBeginDocument
{
\file_if_exist_input:n { \c_sys_jobname_str.thm }
\iow_open:Nn \g_student_theorems_statements_iow { \c_sys_jobname_str.thm }
}
\ExplSyntaxOff
\declaretheorem[within=section]{theorem}
\declaretheorem[sibling=theorem]{lemma}
\begin{document}
\section{First}
\begin{theorem}
This is a normal theorem.
\end{theorem}
\begin{proof}
Which has a proof.
\end{proof}
\theoremstatement{A}{theorem}
\section{Second}
\theoremstatement{B}{lemma}
\appendix
\section{Statements and proofs}
\begin{delayedtheorem}{A}{theorem}
This is a theorem whose proof is in the appendix.
\end{delayedtheorem}
\begin{proof}
And its proof.
\end{proof}
\begin{delayedtheorem}{B}{lemma}[With name]
A boring lemma.
\end{delayedtheorem}
\begin{proof}
Even more boring proof.
\end{proof}
\end{document}