Skip to content

Commit

Permalink
Merge pull request #9 from sebaseb98/i-figured
Browse files Browse the repository at this point in the history
Use i-figured for section-based equation numbering
  • Loading branch information
sebaseb98 authored Nov 22, 2024
2 parents 1dcbd9c + 01ab890 commit 56499ff
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 33 deletions.
87 changes: 62 additions & 25 deletions lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "@preview/great-theorems:0.1.1": great-theorems-init
#import "@preview/hydra:0.5.1": hydra
#import "@preview/equate:0.2.1": equate
#import "@preview/i-figured:0.2.4": reset-counters, show-equation
#import "@preview/headcount:0.1.0": reset-counter

#let mathcounter = counter("mathblocks") // counter for mathblocks
Expand Down Expand Up @@ -37,7 +38,7 @@

// equation settings
equate-settings: none,
numbering-pattern: "(1.1)",
equation-numbering-pattern: "(1.1)",

// the content of the thesis
body
Expand All @@ -51,28 +52,56 @@ show ref: set text(fill: link-color)

// ------------------- Math equation settings -------------------

set math.equation(numbering: numbering-pattern) if equate-settings != none
// only labeled equations get a number
// either use equate if equate-settings is set or use i-figured if equate-settings is none
// i-figured settings
show math.equation: it => {
if equate-settings == none {
show-equation(prefix: "eq:", only-labeled: true, numbering: equation-numbering-pattern, it)
} else {
it
}
}
set math.equation(supplement: none) if equate-settings == none

// equate settings
show: it => {
if equate-settings != none {
equate(..equate-settings, it)
} else if it.has("label"){
math.equation(block:true, numbering: numbering-pattern, it)
} else {
it
}
}
set math.equation(numbering: equation-numbering-pattern) if equate-settings != none

// Reference equations with parentheses (for equate)
// cf. https://forum.typst.app/t/how-can-i-set-numbering-for-sub-equations/1603/4
show ref: it => {
let eq = math.equation
let el = it.element
if equate-settings == none and el != none and el.func() == math.equation {

let is-normal-equation = el != none and el.func() == eq
let with-subnumbers = equate-settings != none and equate-settings.keys().contains("sub-numbering") and equate-settings.sub-numbering
let is-sub-equation = el != none and el.func() == figure and el.kind == eq
if equate-settings != none and is-normal-equation {
link(el.location(), numbering(
"(1)",
counter(math.equation).at(el.location()).at(0) + 1
el.numbering,
..counter(eq).at(el.location())
))
} else if equate-settings != none and not with-subnumbers and is-sub-equation {
link(el.location(), numbering(
el.numbering,
counter(eq).at(el.location()).at(0) - 1
))
} else if equate-settings != none and is-sub-equation {
link(el.location(), numbering(
el.numbering,
..el.body.value
))
} else {
it
}
}

show math.equation: box // no line breaks in inline math
show: great-theorems-init // show rules for theorems

Expand All @@ -82,24 +111,23 @@ show heading.where(level: 1): set heading(supplement: [Chapter])
show heading.where(
level: 1,
): it => {
if it.numbering != none{
block(width: 100%)[

#line(length: 100%, stroke: 0.6pt + heading-color)
#v(0.1cm)
#set align(left)
#set text(22pt)
#text(heading-color)[Chapter
#counter(heading).display(
"1:" + it.numbering
)]

#it.body
#v(-0.5cm)
#line(length: 100%, stroke: 0.6pt + heading-color)
]
if it.numbering != none {
block(width: 100%)[
#line(length: 100%, stroke: 0.6pt + heading-color)
#v(0.1cm)
#set align(left)
#set text(22pt)
#text(heading-color)[Chapter
#counter(heading).display(
"1:" + it.numbering
)]

#it.body
#v(-0.5cm)
#line(length: 100%, stroke: 0.6pt + heading-color)
]
}
else{
else {
block(width: 100%)[
#line(length: 100%, stroke: 0.6pt + heading-color)
#v(0.1cm)
Expand Down Expand Up @@ -143,6 +171,15 @@ show heading.where(
linebreak()
}

// reset counter from i-figured for section-based equation numbering
show heading: it => {
if equate-settings == none {
reset-counters(it)
} else {
it
}
}
// from headcount for theorems
show heading: reset-counter(mathcounter, levels: 1)
// ------------------- other settings -------------------
// Settings for Chapter in the outline
Expand Down
15 changes: 9 additions & 6 deletions template/chapter/dummy_chapter.typ
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ $<eq:first_binom>
which is labeled and therefore numbered. We can also reference it: @eq:first_binom.
In the following, we have a multiline equation to demonstrate how `equate` handles it (if activated).
$
15^2 &= (10 + 5)^2 \
&= 10^2 + 2 * 10 * 5 + 5^2 \
15^2 &= (10 + 5)^2 #<eq:sub1>\
&= 10^2 + 2 * 10 * 5 + 5^2 #<eq:sub2>\
&= 100 + 100 + 25 \
&= 225.
$<eq:multi_line_binom>

If `equate` is activated by passing `equate-settings` to the `template`, we can reference a subequation @eq:sub1
or the whole equation @eq:multi_line_binom.
Equations that are not of the same importance can be inline, e.g. $(a + b) (a - b) = a^2 - b^2$ or unlabeled
$
(a - b)^2 = a^2 - 2a b + b^2.
Expand All @@ -76,7 +79,7 @@ Here we have a complicated procedure in @algo:example_algo (using `lovelace`) wh
kind: "algorithm",
supplement: [Algorithm],
pseudocode-list(booktabs: true, numbered-title: [#smallcaps[Example Algorithm]])[
- Input: $A, B, C$
- Input: $A, B, C$
+ *for* $i in {A,B,C}$ #v(1mm)
+ do very fancy stuff
+ #line-label(<line:stopping>)*if* motivation is lost: *break*
Expand Down Expand Up @@ -105,10 +108,10 @@ In @table:irrational_numbers we compare some irrational numbers, my favourite on
table(
columns: 2,
stroke: none,
[], table.vline(stroke: .6pt),[approx. value],
[], table.vline(stroke: .6pt),[approx. value],
table.hline(stroke: .6pt),
[$sqrt(2)$], [#calc.round(calc.sqrt(2), digits: 2)],
[$sqrt(2)$], [#calc.round(calc.sqrt(2), digits: 2)],
[$e$], [#calc.round(calc.exp(1), digits: 2)],
[$pi$], table.cell(fill:green)[#calc.round(calc.pi, digits: 2)],
[$pi$], table.cell(fill:green)[#calc.round(calc.pi, digits: 2)],
)
)<table:irrational_numbers>
Binary file modified template/main.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions template/main.typ
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

// equation settings
equate-settings: (breakable: true, sub-numbering: true, number-mode: "label"),
numbering-pattern: "(1.1)",

equation-numbering-pattern: "(1.1)",
// colors
cover-color: color1,
heading-color: color2,
Expand Down

0 comments on commit 56499ff

Please sign in to comment.