diff options
Diffstat (limited to 'tests/suite/introspection/counter.typ')
| -rw-r--r-- | tests/suite/introspection/counter.typ | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/suite/introspection/counter.typ b/tests/suite/introspection/counter.typ new file mode 100644 index 00000000..8a5315f9 --- /dev/null +++ b/tests/suite/introspection/counter.typ @@ -0,0 +1,78 @@ +// Test counters. + +--- counter-basic-1 --- +// Count with string key. +#let mine = counter("mine!") + +Final: #context mine.final().at(0) \ +#mine.step() +First: #context mine.display() \ +#mine.update(7) +#context mine.display("1 of 1", both: true) \ +#mine.step() +#mine.step() +Second: #context mine.display("I") +#mine.update(n => n * 2) +#mine.step() + +--- counter-basic-2 --- +// Test `counter`. +#let c = counter("heading") +#c.update(2) +#c.update(n => n + 2) +#context test(c.get(), (4,)) +#c.update(n => n - 3) +#context test(c.at(here()), (1,)) + +--- counter-label --- +// Count labels. +#let label = <heya> +#let count = context counter(label).display() +#let elem(it) = [#box(it) #label] + +#elem[hey, there!] #count \ +#elem[more here!] #count + +--- counter-heading --- +// Count headings. +#set heading(numbering: "1.a.") +#show heading: set text(10pt) +#counter(heading).step() + += Alpha +In #context counter(heading).display() +== Beta + +#set heading(numbering: none) += Gamma +#heading(numbering: "I.")[Delta] + +At Beta, it was #context { + let it = query(heading).find(it => it.body == [Beta]) + numbering(it.numbering, ..counter(heading).at(it.location())) +} + +--- counter-page --- +#set page(height: 50pt, margin: (bottom: 20pt, rest: 10pt)) +#lorem(12) +#set page(numbering: "(i)") +#lorem(6) +#pagebreak() +#set page(numbering: "1 / 1") +#counter(page).update(1) +#lorem(20) + +--- counter-figure --- +// Count figures. +#figure(numbering: "A", caption: [Four 'A's], kind: image, supplement: "Figure")[_AAAA!_] +#figure(numbering: none, caption: [Four 'B's], kind: image, supplement: "Figure")[_BBBB!_] +#figure(caption: [Four 'C's], kind: image, supplement: "Figure")[_CCCC!_] +#counter(figure.where(kind: image)).update(n => n + 3) +#figure(caption: [Four 'D's], kind: image, supplement: "Figure")[_DDDD!_] + +--- counter-at-no-context --- +// Test `counter.at` outside of context. +// Error: 2-28 can only be used when context is known +// Hint: 2-28 try wrapping this in a `context` expression +// Hint: 2-28 the `context` expression should wrap everything that depends on this function +#counter("key").at(<label>) |
