-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
docsImprovements or additions to documentationImprovements or additions to documentation
Description
Description
I needed a multi-level counter, but I found that the counter documentation only really discusses single-level counter, which made it much harder than it should have been.
I wanted to index "questions" with numbers of the form S.C, where S is the section counter and C is a question-specific counter. (For example: 1.1, 1.2, then 2.1). Here is the code that I ended up writing:
#let question_counter = counter("question")
#question_counter.update((0, 0))
#show heading: it => {
if it.level == 1 {
question_counter.update((s, c) => (s+1, 0))
}
}
#let question(body) = {
question_counter.update((s, c) => (s, c+1))
strong([ Question #context{ question_counter.display() } ])
body
}
= Example usage
#question[Foo]
#question[Bar]
= More example
#question[Baz]This required too much trial-and-error, I believe that the counter documentation should be improved to make this easy. For example:
- There are no examples of
updatewith multi-level counters. - The behavior of
stepon multi-level counters is not explained.- Does the indexing start at 0 or 1?
Answer: it appears to start at 1. - is
question_counter.step(level: 1)equivalent toquestion_counter.update((s, c) => (s+1, c))or toquestion_counter.update((s, c) => (s+1, 0))?
Answer: in my tests, neither, it appears to be unusable with 2-level counters.
- Does the indexing start at 0 or 1?
- I get weird errors if I remove the
#question_counter.update((0, 0))initialization, why? Is there a way to indicate that a counter is multi-level at creation time?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
docsImprovements or additions to documentationImprovements or additions to documentation