summaryrefslogtreecommitdiff
path: root/tests/typ/meta/counter.typ
blob: 6b5797de08a9d056b6b7936db26fe07f1781bd96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Test counters.

---
// Count with string key.
#let mine = counter("mine!")

Final: #locate(loc => mine.final(loc).at(0)) \
#mine.step()
First: #mine.display() \
#mine.update(7)
#mine.display("1 of 1", both: true) \
#mine.step()
#mine.step()
Second: #mine.display("I")
#mine.update(n => n * 2)
#mine.step()

---
// Count labels.
#let label = <heya>
#let count = counter(label).display()
#let elem(it) = [#box(it) #label]

#elem[hey, there!] #count \
#elem[more here!] #count

---
// Count headings.
#set heading(numbering: "1.a.")
#show heading: set text(10pt)
#counter(heading).step()

= Alpha
In #counter(heading).display()
== Beta

#set heading(numbering: none)
= Gamma
#heading(numbering: "I.")[Delta]

At Beta, it was #locate(loc => {
  let it = query(heading, loc).find(it => it.body == [Beta])
  numbering(it.numbering, ..counter(heading).at(it.location()))
})

---
// 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!_]