Part independent section

You can simplify this by using numbering, counter, and spread operator:

#set heading(numbering: (..nums) => {
  let chapter-count = counter("chapter counter")
  if nums.pos().len() == 1 {
    // Level 1: Roman numerals for Parts.
    numbering("I", ..nums)
  } else if nums.pos().len() == 2 {
    // Level 2: Use the chapter state counter and increment it.
    chapter-count.step()
    str(chapter-count.get().first() + 1)
    // or
    // context numbering("1", ..chapter-count.get())
  } else {
    // Level 3+: Use the chapter number followed by the position within that chapter.
    numbering("1.1", ..chapter-count.get(), ..nums.pos().slice(2))
  }
})

= Part One
== Chapter One
=== Section
== Chapter Two
= Part Two
== Chapter Three
=== Section
=== Section
==== Subsection
==== Subsection
= Part Three
== Chapter Four

image

P.S. By “better include the output” I meant the screenshot of the relevant part of the document (like above). The PDF supposed to be uploaded in case a few shortcuts won’t cut it or a bug-related info is needed. Allow sharing PDF and ZIP files on the forum - #10 by laurmaedje