How to keep continuous numbering of subsections across sections?

Hi everyone :wave:

I’m writing our student body’s statutes in Typst and I’d like the final document to look like this:

§23 Ballot papers

Lorem ipsum dolor sit amet

IV Meetings

§24 Public nature of meetings

Lorem ipsum dolor sit amet

To structure the document, I’m currently using sections and subsections like this:

== Ballot papers  
Lorem ipsum dolor sit amet

= Meetings

== Public nature of meetings  
Lorem ipsum dolor sit amet

This works for hierarchy, but it breaks the continuous numbering of the “§” paragraphs — Typst restarts the numbering after each new = (chapter).

I already tried sillyfreak’s solution from this thread:

#show heading.where(level: 2): set heading(numbering: (_, ..nums) => numbering("§1", ..nums))

but as he mentioned, this approach stops working as soon as the higher-level chapters (=) have their own numbering. And i don’t really get how to adapt the enum solutions from that thread to headings.

Is there a clean way to make all == headings share one continuous counter for the “§” numbers, regardless of what section (=) they appear in?

Or is there another way to structure the document that is more “the typst way”?

Hi. Use a separate counter.

#let section = counter("section")

#show heading.where(level: 1): set heading(numbering: "I")
#show heading.where(level: 2): it => section.step() + it
#show heading.where(level: 2): set heading(
  numbering: (..) => context numbering("§1", ..section.get()),
  // numbering: (..) => sym.section + context numbering("1", ..section.get()),
)

#counter(heading).update(3)
#section.update(22)

== Ballot papers
Lorem ipsum dolor sit amet

= Meetings

== Public nature of meetings
Lorem ipsum dolor sit amet

1 Like

Thank you!

1 Like