I am currently in the process of writing my own letter-template. It should support multiple letters per file, page-numbers and double-sided printing.
I adapted How to reset the page counter after every section? - #10 by laurmaedje to reset the page-counter on each new letter.
But now the page-counter does not account for the fact, that an empty page might have been inserted if the letter was only one page long (because a pagebreak to odd has been inserted in order to support double-sided printing of the letters).
//https://forum.typst.app/t/how-to-reset-the-page-counter-after-every-section/1924/10
#let reset = <__reset>
#let subtotal() = {
let loc = here()
let list = query(selector(reset).after(loc))
if list.len() > 0 {
counter(page).at(list.first().location()).first() - 1
} else {
counter(page).final().first()
}
}
#let page-numbers = context {
let subtotal = subtotal()
//Dont show page-numbers if there is only one page in the letter
if subtotal == 1 {
none
} else {
numbering("1 / 1", ..counter(page).get(), subtotal)
}
}
#let letter(
to: [],
body,
) = {
pagebreak(weak: true, to: "odd")
[#metadata(none)#reset]
counter(page).update(1)
pagebreak(weak: true)
set page(
footer: context {
align(center, page-numbers)
},
)
to
body
}
#show: letter.with(to: [To someone])
#lorem(50)
#show: letter.with(to: [To someone else])
#lorem(1000)
So my question is: How do I adapt the code, so that the subtotal-function in the MWE reports the number of pages in the letter not including the possibly inserted blank page?
Merci.