No, you are pretty much spot on. Here is a slightly modified version:
#set page(paper: "a5")
#show outline.entry.where(level: 1): it => {
let i = counter("i-counter")
i.step()
context if calc.even(i.get().first()) {
strong(it)
} else {
it
}
}
#outline(depth: 3, indent: auto)
= First
= Second
= Third
= Fourth
If you don’t use the counter anywhere else, then it’s a good idea to put it where it is used. You can also use functions like even which will improve readability.
With the counter function, you can access and modify counters for pages, headings, figures, and more. Moreover, you can define custom counters for other things you want to count.
Since counters change throughout the course of the document, their current value is contextual. It is recommended to read the chapter on context before continuing here.
There are many Typst ways… Here is below an approach without a counter, but I think much more expensive, because you query headings in the document.
#show outline.entry.where(level: 1): it => context {
let i = query(heading.where(level: 1).before(it.element.location())).len()
if calc.rem(i, 2) == 1 {
str(i) + "-" + strong(it)
} else {
str(i) + "-" + it
}
}
= A
= B
= C
= D
= E
#outline(depth: 3, indent: auto)
Yeah, that’s great too (more verbose, but doesn’t use a custom counter). I was only thinking by looking at the initial example. But you can slightly improve it:
#set page(paper: "a5")
#show outline.entry.where(level: 1): it => context {
let selector = heading.where(level: 1).before(it.element.location())
let count = query(selector).len() + 1
if calc.even(count) {
strong(it)
} else {
it
}
}
#outline(depth: 3, indent: auto)
= #lorem(6)
= #lorem(6)
= #lorem(6)
= #lorem(6)
= #lorem(6)
= #lorem(6)
Thanks for clearing it up! I did not notice the bug . Although, I still think the counter solution is easier to think of, and might be more performant…