TeX - LaTeX Asked on November 9, 2021
It is quite convenient to use the opmac in Plain TeX, but I still do not know how to type a mathematical theorem with automatic number. At this stage, I am only able to type a theorem manually as:
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
It seems that above Theorem 1.1 can not be referred by "ref".
My question is how to type a slanted theorem with automatic number, so that I can refer it easily.
Any comments and suggestions will be appreciated.
I borrowed the code from CTUstyle macro. Five independent registers A,B,C,D,E are declared here. We reset them in each section, see sechook
definition below. They can be used in numbered paragraphs by macro numberedpar reg{Word}
. For example
deftheorem {numberedpar A{Theorem}}
defcorollary {numberedpar A{Corollary}}
defexample {numberedpar B{Example}}
defnotice {numberedpar C{Notice}}
This example shares numbers for Theorems and Colorraly and there are indepenent numbers for Examples and Notices.
The whole example is here:
input opmac
newcountnumA newcountnumB newcountnumC newcountnumD newcountnumE
defsechook#1relax{numA=0 numB=0 numC=0 numD=0 numE=0
seccnum=0 tnum=0 fnum=0 dnum=0 relax}
defnumberedpar#1#2{par globaladvancecsname num#1endcsname by1
noindentwlabel{thesecnum.thecsname num#1endcsname}%
{bf#2 thesecnum.thecsname num#1endcsname.}space}
deftheorem #1par{numberedpar A{Theorem}{it#1}}
defcorollary #1par{numberedpar A{Corollary}{it#1}}
defexample {numberedpar B{Example}}
defnotice {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
Answered by wipet on November 9, 2021
If you want to preserve the awkward syntax of proclaim
:
input opmac
newcounttheoremcount
defthetheoremcount{thetheoremcount}
deftheorem#1par{%
globaladvancetheoremcount by 1
csname proclaimendcsname
Theorem wlabelthetheoremcountthetheoremcount. ignorespaces#1par
}
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
The documentation of OPmac is rather scanty. If you want to link the theorem number to the section, you have to do it yourself.
input opmac
newcounttheoremcount
defthetheoremcount{thesecnum.thetheoremcount}
defsechook{globaltheoremcount=0 }
deftheorem#1par{%
globaladvancetheoremcount by 1
csname proclaimendcsname
Theorem wlabelthetheoremcountthetheoremcount. ignorespaces#1par
}
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
Answered by egreg on November 9, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP