在 Plain TeX 中使用 opmac 非常方便,但我仍然不知道如何输入带有自动编号的数学定理。现阶段,我只能手动输入定理,如下所示:
\input opmac
\label[sec1]
\sec Test 1
\proclaim Theorem 1.1. This is a test of \TeX.
\sec Test 2
Refer to Section \ref[sec1].
\bye
看来上面的定理1.1不能被“\ref”引用。
我的问题是如何输入带有自动编号的倾斜定理,以便我可以轻松地参考它。
任何意见和建议都将受到赞赏。
答案1
如果你想保留不方便的语法\proclaim
:
\input opmac
\newcount\theoremcount
\def\thetheoremcount{\the\theoremcount}
\def\theorem#1\par{%
\global\advance\theoremcount by 1
\csname proclaim\endcsname
Theorem \wlabel\thetheoremcount\thetheoremcount. \ignorespaces#1\par
}
\label[sec1]
\sec Test 1
\label[thm]
\theorem This is a test of \TeX.
\sec Test 2
Refer to Section \ref[sec1] and to theorem~\ref[thm].
\bye
OPmac 的文档相当少。如果你想将定理编号链接到该部分,你必须自己动手。
\input opmac
\newcount\theoremcount
\def\thetheoremcount{\the\secnum.\the\theoremcount}
\def\sechook{\global\theoremcount=0 }
\def\theorem#1\par{%
\global\advance\theoremcount by 1
\csname proclaim\endcsname
Theorem \wlabel\thetheoremcount\thetheoremcount. \ignorespaces#1\par
}
\label[sec1]
\sec Test 1
\label[thm]
\theorem This is a test of \TeX.
\sec Test 2
Refer to Section \ref[sec1] and to theorem~\ref[thm].
\label[thm2]
\theorem This is a test of \TeX.
Refer to theorem~\ref[thm2].
\bye
答案2
我借用了 CTUstyle 宏的代码。这里声明了五个独立的寄存器 A、B、C、D、E。我们在每个部分重置它们,见\sechook
下面的定义。它们可以通过宏在编号段落中使用\numberedpar reg{Word}
。例如
\def\theorem {\numberedpar A{Theorem}}
\def\corollary {\numberedpar A{Corollary}}
\def\example {\numberedpar B{Example}}
\def\notice {\numberedpar C{Notice}}
此示例为定理和 Colorraly 共享数字,并且示例和通知有独立的数字。
整个例子在这里:
\input opmac
\newcount\numA \newcount\numB \newcount\numC \newcount\numD \newcount\numE
\def\sechook#1\relax{\numA=0 \numB=0 \numC=0 \numD=0 \numE=0
\seccnum=0 \tnum=0 \fnum=0 \dnum=0 \relax}
\def\numberedpar#1#2{\par \global\advance\csname num#1\endcsname by1
\noindent\wlabel{\thesecnum.\the\csname num#1\endcsname}%
{\bf#2 \thesecnum.\the\csname num#1\endcsname.}\space}
\def\theorem #1\par{\numberedpar A{Theorem}{\it#1}}
\def\corollary #1\par{\numberedpar A{Corollary}{\it#1}}
\def\example {\numberedpar B{Example}}
\def\notice {\numberedpar C{Notice}}
\label[sec1]
\sec Test 1
%\proclaim Theorem 1.1. This is a test of \TeX.
\label[TheorX]
\theorem This is Theorem.
\sec Test 2
Refer to Section \ref[sec1] and to Theorem \ref[TheorX].
\bye