I am creating a custom template for a book, and I would like the front matter (title page, outline, copyright, etc) to use Roman page numbers (i, ii, iii, …)
Then, the rest of the book (starting with chapter 1) should use Arabic page numbers (1, 2, 3…).
One way to achieve this is to create functions such as
#let frontmatter(body) = {
set page(numbering: "i")
body
}
and similarly for mainmatter(body). However, the user of the file would then have to write
#frontmatter[
titlepage()
#outline()
]
i.e. wrap everything inside [ ]. Similarly for the mainmatter(), all content has to be wrapped. Is this perhaps the Typst “way”?
As an alternative, I have done the following:
// template.typ
#let stat = state("p-num", "roman")
#let template(body) = {
set page(
numbering: (current, ..total) => context {
if stat.get() == "roman" {
numbering("i", current)
} else {
numbering("1", current)
}
}
)
body
}
#let frontmatter() = {
stat.update("roman")
}
#let mainmatter() = {
stat.update("arabic")
}
i.e. I use a state variable stat to keep track of the page numbering style, and use the functions frontmatter() and mainmatter() to update state. Note that, here, I do not need to wrap all the front matter content inside [ ].
This works the actual page numbers, but fails in the outline/table of contents which still displays Roman numbers, even for pages that has Arabic numberings.
For anyone wanting to test this out, here is a test file to check this. (This does not use the functions frontmatter() and mainmatter(), but the result is the same even if those are used.)
// test.typ
#import "mini.typ": *
#show: template
#outline()
#pagebreak()
#stat.update("arabic")
// #set page(numbering: "1")
= First chapter
#lorem(100)
= Second chapter
#lorem(100)
#pagebreak()
= Third chapter
#lorem(100)
So, my question is: should I stick to the function version (first one above) where I simply wrap the different matter parts in [ ], or should I try to find a fix for the problems with outline, and use the second version? In that case, does anyone know how to fix the outline so that it uses the actual page numbers for each page?
Being used to LaTeX I tend to like the state switching, and it also feels like the state variables are meant for problems like these.