Reduced code duplication, added other environments.

Added the remark, corrolary, and example environments.
This commit is contained in:
orca 2024-01-17 05:21:13 +01:00
parent 56320264af
commit 7157b184d1
Signed by: orca
GPG Key ID: 6923B8DFED96A68A
1 changed files with 45 additions and 69 deletions

View File

@ -3,15 +3,23 @@
// Constants.
// The QED sign - a square drawn with four strokes.
#let qed = [$square.stroked$]
// Language-specific constants.
#let lang = "fr"
// Environments name.
#let outline-title = [Table des matières]
#let abstract-begin = "Résumé"
#let theorem-begin = "Théorème"
#let proposition-begin = "Propostition"
#let lemma-begin = "Lemme"
#let definition-begin = "Définition"
#let proof-begin = "Démonstration"
#let abstract-text = "Résumé"
#let proposition-text = "Propostition"
#let lemma-text = "Lemme"
#let theorem-text = "Théorème"
#let corrolary-text = "Théorème"
#let definition-text = "Définition"
#let remark-text = "Remarque"
#let example-text = "Exemple"
#let proof-text = "Démonstration"
// Number the equations starting with the heading hierarchy before them.
// E.g. if we are looking at the 6th equation in the 4th subheading
@ -19,84 +27,52 @@
#let numbering-equation(equation) = [(#counter(heading).display()#equation)]
#let numbered-equation(body) = math.equation(numbering: numbering-equation, block: true)[#body]
// The QED sign - a square drawn with four strokes.
#let qed = [$square.stroked$]
// Functions.
// Empathize text by putting it in a very light filled gray box.
#let block-emph-fill(body, intensity: 10) = {
rect(fill: rgb(0, 0, 0, intensity), width: 100%, radius: 1pt)[#body]
#let block-emph(body, way: "") = {
if way == "fill" {
// Empathize text by putting it in a very light filled gray box.
rect(fill: rgb(0, 0, 0, 10), width: 100%, radius: 1pt)[#body]
} else if way == "outline" {
// Empathize text by putting it in a very light gray box.
rect(stroke: rgb(0, 0, 0, 18) + 4pt, width: 100%, radius: 1pt)[#body]
} else {
[#body]
}
}
// Empathize text by putting it in a very light gray box.
#let block-emph-outline(body, intensity: 18) = {
rect(stroke: rgb(0, 0, 0, intensity) + 4pt, width: 100%, radius: 1pt)[#body]
}
// Create a theorem environment.
// We create a counter to be able to index the theorem.
#let theorem-counter = counter("theorem")
// The `name` named variable allows us to give a name to a theorem.
// E.g, `#theorem("Euclid")[<...>]` gives [#theorem-begin (Euclid). <...>].
#let theorem(body, name: "") = {
theorem-counter.step()
// The `name` named variable allows us to give a name to be displayed instead of the numbers.
#let math-block(body, name: "", kind: "", emphasis: "bold", decoration: "fill") = {
// We create a counter to be able to index the environment.
let current-counter = counter(kind)
let id = if name == "" {
counter(heading).display() + theorem-counter.display()
current-counter.step()
counter(heading).display() + current-counter.display()
} else {
"(" + name + ")"
}
block-emph-fill[*#theorem-begin #id.* #body]
}
// Behaves like theorem, but with a different counter.
#let proposition-counter = counter("proposition")
#let proposition(body, name: "") = {
proposition-counter.step()
let id = if name == "" {
counter(heading).display() + proposition-counter.display()
if emphasis == "bold" {
block-emph(way: decoration)[*#kind #id.* #body]
} else if emphasis == "italics" {
block-emph(way: decoration)[_#kind #id._ #body]
} else {
"(" + name + ")"
block-emph(way: decoration)[#kind #id. #body]
}
block-emph-fill[*#proposition-begin #id.* #body]
}
// Behaves like theorem, but with a different counter.
#let lemma-counter = counter("lemma")
#let lemma(body, name: "") = {
lemma-counter.step()
let id = if name == "" {
counter(heading).display() + lemma-counter.display()
} else {
"(" + name + ")"
}
block-emph-fill[*#lemma-begin #id.* #body]
}
// Behaves like theorem, but with a different counter and a different emphasis.
#let definition-counter = counter("definition")
#let definition(body, name: "") = {
definition-counter.step()
let id = if name == "" {
counter(heading).display() + definition-counter.display()
} else {
"(" + name + ")"
}
block-emph-outline[_#definition-begin #id._ #body]
}
#let proposition(body, name: "") = math-block(body, name: name, kind: proposition-text)
#let lemma(body, name: "") = math-block(body, name: name, kind: lemma-text)
#let theorem(body, name: "") = math-block(body, name: name, kind: lemma-text)
#let corrolary(body, name: "") = math-block(body, name: name, kind: lemma-text)
#let definition(body, name: "") = math-block(body, name: name, kind: definition-text, emphasis: "italics", decoration: "outline")
#let remark(body, name: "") = math-block(body, name: name, kind: remark-text, decoration: "none")
#let example(body, name: "") = math-block(body, name: name, kind: example-text, decoration: "none")
// It takes the body of the proof, and formats it by adding the QED
// symbol at the end, and the _#proof-begin._ text at the front.
#let proof(body) = [
_#proof-begin._ #body #h(3em) #place(right, clearance: 20em, dy: -7pt, qed)
]
// symbol at the end, and the _#proof-text._ text at the front.
#let proof(body) = [_#proof-text._ #body #h(3em) #place(right, dy: -7pt, qed)]
// Configuration of the paper.
@ -152,7 +128,7 @@
if abstract != [] {
par(justify: false)[
#smallcaps[#abstract-begin] \
#smallcaps[#abstract-text] \
#v(0.15em)
#abstract
#v(2em)