I’m trying to add a variable to my template where the user can set a custom page numbering schema (Customize Page Numbering Format · Issue #18 · DannySeidel/typst-dhbw-template · GitHub). Due to the template using multiple different numbering styles, I want to enable the user to customize all sections.
I have a preface part that uses Roman numbering like this I
. After that, the template shows the main part, which uses Arabic numbering like this 1 / 1
. Lastly, the template uses Latin letters for the appendix section like this a
. Because the main section provides the total number of pages, I had to define a custom footer because the page counter does not provide the number of pages at a specific point in the document.
Currently, I create the footer as shown below:
set page(footer: context align(
numbering-alignment,
numbering(
"1 / 1",
..counter(page).get(),
..counter(page).at(<numbering-main-end>),
),
))
By using counter(page).at(<numbering-main-end>)
, I get the number of pages at this label. Because the user should be able to set the style for all three sections, I have now created labels at the end of all three sections. The problem is that if the user defines a style that does not contain the total number of pages, I still pass in the counter, and the number is still displayed. If I leave out the total count and the user defines a style with the total number of pages displayed, the total number of pages is shown as 1, as the data is missing.
How would I solve this problem? Maybe I could conditionally pass in the total number of pages only if it is needed? But how?