I generate my books using mdbook-typst and have a nice template for my project:
#let template(
title: [Book title],
author: "Author",
paper-size: "a5",
dedication: none,
publishing-info: none,
body,
) = {
set document(title: title, author: author)
set text(font: "Libertinus Serif")
set page(
paper: paper-size,
margin: (bottom: 1.75cm, top: 2.25cm),
)
...
I would like to set the page numbering format and counter from that template so that every time I generate a book, it get it right.
To achieve the result, at the moment, I have to insert manually:
#set page(numbering: "i")
#counter(page).update(1)
before my introduction in my .typst
main document and:
#set page(numbering: "1")
#counter(page).update(1)
before the first part of the book.
I have tried to play around with the rules, such like:
set page(
footer: context [
#set align(center)
#let (num,) = counter(page).get()
#let p = here().page()
#let allLevel1Heading = query(selector(heading.where(level: 1)))
#let firstPage = allLevel1Heading.at(0).location().page()
#let secondPage = allLevel1Heading.at(1).location().page()
#let thirdPage = allLevel1Heading.at(2).location().page()
#if (p > firstPage + 1 and p < secondPage - 1){
counter(page).display("i")
}
#if (p > secondPage and p != thirdPage){
counter(page).display("1")
}
]
)
And adding rule to reset the counter, but I realized that it is impossible to reset the counter from the template alone. Is there another solution ?