I am currently working on a template that has some template content after the users content. This leads to the max page number to be “wrong” in the content section when using “1 / 1” or similar as numbering format.
// content
#set page(numbering: "1 / 1")
#counter(page).update(1)
#lorem(9999)
// appendix
#set page(numbering: "i")
#counter(page).update(1)
#lorem(999)
This is a minimal version showing this problem: lorem(999) produces two pages, leading to the footer in the content section showing “x / 2”, even though the content section has 15 pages.
The easy solution would probably to use a label selector to find the last page of the content section and built the “1 / 1” numbering with a custom function. This is not viable in my situation, as the numbering should be customizable by the user. The user should be able to set the numbering to their liking with a single parameter (numbering-content).
How do I fix the wrong max page in “1 / 1” numbering styles, without receiving additional information from a template user?
The user should be able to set numbering-content to “1 / 1”, “I”, or whatever they want.
Hi @Marvin_Fuchs.
This has been resolved before (duplicate).
Multiple sections
Please have a look at the solution from How to reset the page counter after every section? - #10 by laurmaedje
Only one section - To switch from arabic to roman
You can also use a shorter solution from How can I switch from Roman to Arabic page numbers without breaking the total page count? - #2 by janekfleper
#let arabic-numbering(..n) = context {
numbering("1 / 1", n.at(0), ..counter(page).at(<last-arabic-page>))
}
// content
#set page(numbering: arabic-numbering)
#counter(page).update(1)
#lorem(9999)
#metadata("last-arabic-page") <last-arabic-page>
// appendix
#set page(numbering: "i")
#counter(page).update(1)
#lorem(999)
3 Likes
Hey @vmartel08, I tried out your solution and this fixes the issue of having a wrong max-page count. However still does not fix the issue of allowing a template user to easily switch between a “1 / 1” and “1” numbering style. In your example when using “1” instead of “1 / 1” it will change a footer like “3 / 13” to “313” because
If numbering is a pattern and more numbers than counting symbols are given, the last counting symbol with its prefix is repeated. (Numbering Function – Typst Documentation)
Is there a nice approach to this problem?
I don’t think there is a way to have it as ‘user-friendly’ as you want it.
you want to allow the user to choose between quite different styles. typst gives you all the possibilities to allow all of these styles but it needs some programming as you can see vmartel08’s answer.
If you want to have it that user-friendly you would need to implement all of the ways that you want to be possible for the user and wrap them in a user-friendly way.
(Let me know if you need more help for that. It would then be beneficial to know what ways you want to enable for the user)
Thank @Xodarap this is what I expected unfortunately.
As a limiting “workaround” we’ll allow the user to make a choice between predefined numbering styles (“1” or “1 / 1” in our case) instead of letting the user define a numbering function/parameter.
If someone has a similar problem in the future there would be a different workaround that allows more customization for template users:
// user
#let custom-numbering-with-max-page(curr, max) = {
numbering("1 / 1", curr, max)
}
#let custom-numbering-without-max-page(curr, max) = {
numbering("1", curr)
}
// template property
#let used-numbering = custom-numbering-with-max-page
// template
// content
#set page(numbering: (..n) => {
used-numbering(n.at(0), ..counter(page).at(<last-content-page>))
})
#counter(page).update(1)
#lorem(9999)
#metadata("last-content-page") <last-content-page>
// appendix
#set page(numbering: "i")
#counter(page).update(1)
#lorem(999)
The user provides a wrapped numbering function. The user implemented function receives the current page and the correct max page. This allows the user to call the numbering function with the correct arguments.