#set heading(numbering: (n, ..nums) => {
assert(n > 0, message: "n = " + repr(n))
[#n is not zero.]
})
= Heading
![]()
The above code compiles in typst v0.13.1, but panics with Assertion failed: n = 0 in typst v0.14.0-rc.2. Why?
error: assertion failed: n = 0
┌─ <stdin>:2:2
│
2 │ assert(n > 0, message: "n = " + repr(n))
│ ^^^^^^^^^^^^^^^^^^
Moreover, if I remove the assert line, then v0.14.0-rc.2 also generates 1 is not zero. How can it be?
Use case
Sometimes we want a Chapter zero, but the numbering function only accepts nonnegative numbers.
#set heading(
- numbering: n => numbering("第一章", n - 1), // v0.13.1
+ numbering: n => numbering("第一章", calc.max(n - 1, 0)), // v0.14.0; calc.abs also works
)
(I know that the chapter zero is for sections before the first chapter, but such sections do not always exist.)
Edits
Edit: This post also applies to the final v0.14.
Edit 2: There’s a related issue. Start a counter with zero? · Issue #6662 · typst/typst · GitHub
Edit 3: Laurenz Mädje commented on it:
the problem is that the heading numbering is resolved during synthesis now because it is needed for the PDF outline and synthesis doesn’t have the error delaying properties of show rules. probably it should have it too. I’m not sure I would consider it a bug per se as numbering functions are supposed to deal with the full set of possible inputs, but it is something that will probably work again in the future so I guess we can track it as a regression.
(Discord, 2025-11-20)
Edit 4: Heading numbering resolution change in 0.14 · Issue #7428 · typst/typst · GitHub