"1 / 1" numbering: How to get correct max page number while allowing customization?

I fail to see where providing some preset numbering styles and applying a style by default could prevent the passing of custom numbering functions.

Rather than being a limitation or a workaround, allowing the user to choose between:

  • default numbering from the template
  • preset numbering with or without total number of pages (per section)
  • custom numbering (pattern or function)

feels more like a demonstration of Typst’s composability. This is a positive aspect and it allows easy configuration for most cases as well as full control in the case it is needed.

A few extra examples as I do agree the docs on numbering are not always easy to decipher especially with regards to numbering functions:

// Total number of pages for example only (need further treatment for section pages)
#let template-numberings = (
  "1",
  "1/1",
  (p, t) => numbering("i/i", p, t),
  (p, _) => numbering("i", p),
  (p, t) => [Page #numbering("i", p) of #numbering("i", t)],
  (p, _) => [Page #numbering("i", p)],
  (..nums) => [Page #numbering("i")],
  (..nums, last) => [-- 1 a i I -- #numbering("i") of #numbering("i", last)],
)

#for preset in template-numberings {
  page(
    paper: "a8",
    numbering: preset,
    lorem(50),
  )
}

From the user side, it would look like:

#import "template.typ": *

//User defined numbering not available in template presets
#let my-num-fr(p, t) = text(blue, [Page #numbering("1", p) de #numbering("1", ..section-total()) ])

#show: document.with(
  paper: "a8", // Pass any `page` arguments
  // Default numbering is "1 / 1" (section total)
  // numbering: numbering-presets.circles-numbering, // Preset
  // numbering: my-num-fr,  // User defined
  // numbering: "⓵",
  // numbering: none, 
)

= Content
#lorem(150)

#show: appendix.with(
  flipped: true // Pass any `page` arguments
  // Default numbering is "Page i of i" (section total)
  //numbering: my-num-fr, 
  //numbering: none,
) 
= Appendix
#lorem(100)

See this example project on Typst.app for a working solution of the Only one section case.

I believe this fulfills all of the requirements posted above:

  • a main document with appendix section
  • total section numbers per section
  • switching from 1 to 1/1 easily
  • capacity to use counting symbols in the functions (like a in page)
  • possibility of using some user defined patterns or functions
  • packaged as a template.