Simple question here: In order to make a template more flexible, I would like to include page numbers if and only if the document has more than one page. How do I do this? The following code leads to an error (“variables from outside the context expression are read-only and cannot be modified”):
#set page(width: 5cm, height: 5cm)
#let page-numbering = none
#context {
if counter(page).final().first() > 1 {
page-numbering = "1"
}
}
#set page(numbering: page-numbering)
text on first page
#pagebreak()
text on second page
I couldn’t find a way to scope context only around the if-condition either , e.g. like so:
If you really want to “disable” the numbering for a single page, you can use the following function
#let page-numbering(i, last) = if last > 1 { numbering("1", i) }
#set page(numbering: page-numbering)
Typst automatically passes the current value of the page counter and the last value of the page counter to the numbering function. I would expect this to be equivalent to looking up counter(page).last().
As an alternative, you could also hide the page number in the footer (or wherever you are currently displaying it).