diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-19 10:19:24 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-19 10:19:34 +0100 |
| commit | 0ba99ab8aa523645e2f0a0d9f6333ad4e48f5daa (patch) | |
| tree | 2de7ce344b6d579dca8ae346c68b1931a6e79b25 /tests/typ | |
| parent | c7f4d6b12ee3138c752402889eeaa603ac69351d (diff) | |
Measurement and introspection rework
Diffstat (limited to 'tests/typ')
| -rw-r--r-- | tests/typ/layout/page-marginals.typ | 4 | ||||
| -rw-r--r-- | tests/typ/meta/counter.typ | 18 | ||||
| -rw-r--r-- | tests/typ/meta/query.typ | 42 | ||||
| -rw-r--r-- | tests/typ/meta/state.typ | 19 |
4 files changed, 72 insertions, 11 deletions
diff --git a/tests/typ/layout/page-marginals.typ b/tests/typ/layout/page-marginals.typ index d8ce9b79..d65591e6 100644 --- a/tests/typ/layout/page-marginals.typ +++ b/tests/typ/layout/page-marginals.typ @@ -6,8 +6,8 @@ h(1fr) text(0.8em)[_Chapter 1_] }, - footer: align(center)[\~ #counter(page).get() \~], - background: counter(page).get(n => if n <= 2 { + footer: align(center)[\~ #counter(page).display() \~], + background: counter(page).display(n => if n <= 2 { place(center + horizon, circle(radius: 1cm, fill: luma(90%))) }) ) diff --git a/tests/typ/meta/counter.typ b/tests/typ/meta/counter.typ index 539af6b9..c3b97629 100644 --- a/tests/typ/meta/counter.typ +++ b/tests/typ/meta/counter.typ @@ -4,21 +4,21 @@ // Count with string key. #let mine = counter("mine!") -Final: #mine.final() \ +Final: #locate(loc => mine.final(loc).at(0)) \ #mine.step() -First: #mine.get() \ +First: #mine.display() \ #mine.update(7) -#mine.both("1 of 1") \ +#mine.display("1 of 1", both: true) \ #mine.step() #mine.step() -Second: #mine.get("I") +Second: #mine.display("I") #mine.update(n => n * 2) #mine.step() --- // Count labels. #let label = <heya> -#let count = counter(label).get() +#let count = counter(label).display() #let elem(it) = [#box(it) #label] #elem[hey, there!] #count \ @@ -31,13 +31,19 @@ Second: #mine.get("I") #counter(heading).step() = Alpha +In #counter(heading).display(). + == Beta -In #counter(heading).get(). #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.id())) +}) + --- // Count figures. #figure(numbering: "A", caption: [Four 'A's])[_AAAA!_] diff --git a/tests/typ/meta/query.typ b/tests/typ/meta/query.typ index 85608e8e..38eadfab 100644 --- a/tests/typ/meta/query.typ +++ b/tests/typ/meta/query.typ @@ -7,7 +7,9 @@ header: { smallcaps[Typst Academy] h(1fr) - query(heading, (before, after) => { + locate(it => { + let after = query(heading, after: it) + let before = query(heading, before: it) let elem = if before.len() != 0 { before.last() } else if after.len() != 0 { @@ -28,3 +30,41 @@ = Approach #lorem(60) + +--- +#set page( + paper: "a7", + numbering: "1 / 1", + margin: (bottom: 1cm, rest: 0.5cm), +) + +#set figure(numbering: "I") +#show figure: set image(width: 80%) + += List of Figures +#locate(it => { + let elements = query(figure, after: it) + for it in elements [ + Figure + #numbering(it.numbering, + ..counter(figure).at(it.id())): + #it.caption + #box(width: 1fr, repeat[.]) + #counter(page).at(it.id()).first() \ + ] +}) + +#figure( + image("/glacier.jpg"), + caption: [Glacier melting], +) + +#figure( + rect[Just some stand-in text], + caption: [Stand-in text], +) + +#figure( + image("/tiger.jpg"), + caption: [Tiger world], +) diff --git a/tests/typ/meta/state.typ b/tests/typ/meta/state.typ index dd34deac..8dfab05b 100644 --- a/tests/typ/meta/state.typ +++ b/tests/typ/meta/state.typ @@ -1,18 +1,33 @@ // Test state. --- +#let s = state("hey", "a") +#let double(it) = 2 * it + +#s.update(double) +#s.update(double) +$ 2 + 3 $ +#s.update(double) + +Is: #s.display(), +Was: #locate(id => { + let it = query(math.equation, id).first() + s.at(it.id()) +}). + +--- #set page(width: 200pt) #set text(8pt) #let ls = state("lorem", lorem(1000).split(".")) #let loremum(count) = { - ls.get(list => list.slice(0, count).join(".").trim() + ".") + ls.display(list => list.slice(0, count).join(".").trim() + ".") ls.update(list => list.slice(count)) } #let fs = state("fader", red) #let trait(title) = block[ - #fs.get(color => text(fill: color)[ + #fs.display(color => text(fill: color)[ *#title:* #loremum(1) ]) #fs.update(color => color.lighten(30%)) |
