In your second approach, it looks like that current_child_count is always zero in Typst鈥檚 first layout run. As a result, we are creating another enum(..., start: 0) in show enum.where(start: 0), causing the maximum show rule depth exceeded error.
You can circumvent it by adding a if guard:
#show enum.where(start: 0): it => {
let args = it.fields()
for i in args.remove("children") {
enum_child_counter.step()
context {
let current_child_count = enum_child_counter.get().first()
if current_child_count > 0 { // 馃憟 Exclude the recursive case
enum(..args, start: current_child_count, i)
}
}
}
}
Related links:
- How to continue `enum` throughout entire document? - #6 by Mc-Zen
- Resumable enum numbering 路 Issue #325 路 typst/typst 路 GitHub
- Mention `heading` in the docs for `enum` 路 Issue #8222 路 typst/typst 路 GitHub
When you define and use a custom counter, in general, you should first step the counter and then display it. This way, the stepping behaviour of a counter can depend on the element it is stepped for.
(Personally speaking, I think that鈥檚 only relevant to multi-level counts.)