typst-theorems


Contents

typst-theorems






base

thmenv
thmboxthmplain
thmproofproof-bodyfmtqedhere
thmrules

1. Introduction
typst-theoremsTypsttheorem
\newtheoremLaTeX
theorem environmentnumbering
state
eoremsLemmas

Corollarieseorem


label
2. Using typst-theorems
typst-theorems
#import "theorems.typ": *
#show: thmrules
thmenv
thmenvthmboxthmplainthmproof
thmenv
3. Feature demonstration
theorem environmentsthmboxthmenv

#let theorem = thmbox(
"theorem", // identifier
"Theorem", // head
fill: rgb("#e8e8f8")
)


#theorem("Euclid")[
There are infinitely many primes.
] <euclid>

eorem 3.1 
nametheoremheading
theorem
<euclid>@euclid

Lemmas
#let lemma = thmbox(
"theorem", // identifier - same as that of theorem
"Lemma", // head
fill: rgb("#efe6ff")
)
#lemma[
If $n$ divides both $x$ and $y$, it also divides $x - y$.
]
Lemma 3.2 
aachCorollaries

#let corollary = thmbox(
"corollary", // identifier
"Corollary", // head
base: "theorem", // base - use the theorem counter
fill: rgb("#f8e8e8")
)
#corollary(numbering: "1.1")[
If $n$ divides two consecutive natural numbers, then $n = 1$.
]
Corollary 3.2.1 
numbering

3.1. Proofs
thmproof
#let proof = thmproof("proof", "Proof")
#proof([of @euclid])[
Suppose to the contrary that $p_1, p_2, dots, p_n$ is a finite enumeration
of all primes. Set $P = p_1 p_2 dots p_n$. Since $P + 1$ is not in our list,
it cannot be prime. Thus, some prime factor $p_j$ divides $P + 1$. Since
$p_j$ also divides $P$, it must divide the difference $(P + 1) - P = 1$, a
contradiction.
]
Proofof eorem3.1 
󰅨
󰆗

󰋴


󰅨
󰆗

󰋴
 

󰋰
 
󰋰
  

qedhere

#theorem[
There are arbitrarily long stretches of composite numbers.
]
#proof[
For any $n > 2$, consider $
n! + 2, quad n! + 3, quad ..., quad n! + n #qedhere
$
]
eorem 3.1.1 
Proof  
     
Cautionqedhere
thmrules
#show: thmrules.with(qed-symbol: $square$)
3.2. Suppressing numbering
numbering: none

#let example = thmplain(
"example",
"Example"
).with(numbering: none)
#example[
The numbers $2$, $3$, and $17$ are prime.
]
Example 
thmplainthmbox

#lemma(numbering: none)[
The square of any even number is divisible by $4$.
]
#lemma[
The square of any odd number is one more than a multiple of $4$.
]
Lemma 
Lemma 3.2.1 
Lemmanot

#lemma(number: "42")[
The square of any natural number cannot be two more than a multiple of 4.
]
Lemma 42 
not
3.3. Limiting depth
base
#let definition = thmbox(
"definition",
"Definition",
base_level: 1, // take only the first level from the base
stroke: rgb("#68ff68") + 1pt
)
#definition("Prime numbers")[
A natural number is called a _prime number_ if it is greater than $1$ and
cannot be written as the product of two smaller natural numbers. <prime>
]
Definition 3.1 prime number

not
#definition("Composite numbers")[
A natural number is called a _composite number_ if it is greater than $1$
and not prime.
]
Definition 3.2 composite number

base_levelbase
#example(base_level: 4, numbering: "1.1")[
The numbers $4$, $6$, and $42$ are composite.
]
Example 3.3.0.0.1 
3.4. Custom formatting
thmboxtitlenamebody
titleheadnumber
#let proof-custom = thmplain(
"proof",
"Proof",
base: "theorem",
titlefmt: smallcaps,
bodyfmt: body => [
#body #h(1fr) $square$ // float a QED symbol to the right
]
).with(numbering: none)
#lemma[
All even natural numbers greater than 2 are composite.
]
#proof-custom[
Every even natural number $n$ can be written as the product of the natural
numbers $2$ and $n\/2$. When $n > 2$, both of these are smaller than $2$
itself.
]
Lemma 3.4.1 
 
 
thmenv   identifierbase
base_levelfmt
#let notation = thmenv(
"notation", // identifier
none, // base - do not attach, count globally
none, // base_level - use the base as-is
(name, number, body, color: black) => [
// fmt - format content using the environment
// name, number, body, and an optional color
#text(color)[#h(1.2em) *Notation (#number) #name*]:
#h(0.2em)
#body
#v(0.5em)
]
).with(numbering: "I") // use Roman numerals
#notation[
The variable $p$ is reserved for prime numbers.
]
#notation("for Reals", color: green)[
The variable $x$ is reserved for real numbers.
]
Notation (I)  
Notation (II) for Reals 
color: green
fmtfmt
"for Reals"name
fmt
#lemma(title: "Lem.", stroke: 1pt)[
All multiples of 3 greater than 3 are composite.
]
Lem. 3.4.2 
titleheadstrokefmt
thmboxblockthmbox
3.5. Labels and references
<label>@

Recall that there are infinitely many prime numbers via @euclid.

You can reference future environments too, like @oddprime[Cor.].

#lemma(supplement: "Lem.", refnumbering: "(1.1)")[
All primes apart from $2$ and $3$ are of the form $6k plus.minus 1$.
] <primeform>
You can modify the supplement and numbering to be used in references, like
@primeform.
Lemma 3.5.1 

Cautionthmenv#show link:
3.6. Overriding base
#let remark = thmplain("remark", "Remark", base: "heading")
#remark[
There are infinitely many composite numbers.
]
#corollary[
All primes greater than $2$ are odd.
] <oddprime>
#remark(base: "corollary")[
Two is a _lone prime_.
]
Remark 3.6.1 
Corollary 3.5.1.1 
Remark 3.5.1.1.1 lone prime
remarkheading
corollary
4. Function reference
4.1. thmenv
thmenvtheorem environment
#let thmenv(
identifier, // environment counter name
base, // base counter name, can be "heading" or none
base_level, // number of base number levels to use
fmt // formatting function of the form
// (name, number, body, ..args) -> content
) = { ... }
fmtnamenumberbody
args
theorem environment
(
..args,
body, // body content
number: auto, // number, overrides numbering if present
numbering: "1.1", // numbering style, can be a function
refnumbering: auto, // numbering style used in references,
// defaults to "numbering"
supplement: identifier, // supplement used in references
base: base, // base counter name override
base_level: base_level // base_level override
) -> content
args
name
argsfmt
thmenv
4.2. thmbox and thmplain
thmboxthmenvfmt
#let thmbox(
identifier, // identifier
head, // head - common name, used in the title
..blockargs, // named arguments, passed to #block
supplement: auto, // supplement for references, defaults to "head"
padding: (top: 0.5em, bottom: 0.5em),
// box padding, passed to #pad
namefmt: x => [(#x)], // formatting for name
titlefmt: strong, // formatting for title (head + number)
bodyfmt: x => x, // formatting for body
separator: [#h(0.1em):#h(0.2em)],
// separator inserted between name and body
base: "heading", // base - defaults to using headings
base_level: none, // base_level - defaults to using base as-is
) = { ... }
thmboxblock
(
width: 100%,
inset: 1.2em,
radius: 0.3em,
breakable: false,
)
thmplainthmbox
#let thmplain = thmbox.with(
padding: (top: 0em, bottom: 0em),
breakable: true,
inset: (top: 0em, left: 1.2em, right: 1.2em),
namefmt: name => emph([(#name)]),
titlefmt: emph,
)
4.3. thmproof, proof-bodyfmt and qedhere
thmproofthmplain
#let thmproof(..args) = thmplain(
..args,
namefmt: emph,
bodyfmt: proof-bodyfmt,
..args.named()
).with(numbering: none)
proof-bodyfmtbodyfmt

#qedhere

4.4. thmrules
thmrules

#let thmrules(
qed-symbol: $qed$, // QED symbol used in proofs
doc
) = { ... }
5. Acknowledgements

base_levelbase: none
separator: ...

fmt
number: ...
title: ...thmbox


