Different page numbering for frontmatter and main content using Typst template

I had not included the frontmatter in the ToC, so I didn’t notice the problem until you pointed it out.

This revised version (written with help from Grok) fixed the mismatch between the page numbering and the ToC by putting numbering outside of the footer function.

#let intro-start-page = state("intro-start-page", none) // store final intro page after layout

#set page(
  numbering: (n) => {
    // locate gives the final layout page of <introduction>, not the current page
    let intro-loc = locate(<introduction>)
    intro-start-page.update(intro-loc.page()) // needed because early passes are unstable

    let intro-page = intro-start-page.get()
    let current-page = here().page() // page we are numbering right now

    if intro-page == none or current-page < intro-page { numbering("i", n) }
    else { numbering("1", n) }
  },

  footer: context {
    let current-page = here().page()
    let intro-page = locate(<introduction>).page()

    // update(0) so next page becomes 1 (Typst increments before display)
    if current-page == intro-page - 1 { block(counter(page).update(0)) }

    if current-page == 1 { return none } // no footer on title page

    set text(10pt)
    align(left)[ $short-title$ #h(1fr) #counter(page).display() ]
  },
)