The only way I’ve been able to style headers in the past is to set text in my template for the whole document and then adjust the font/size within each chapter for the paragraph/body content.
and in the chapters I have this - including my alternating header text function:
#import "template.typ": *
#show: template
#set page(
header: context {
let page = counter(page).get().first()
let body = if calc.odd(page) [_title_ | #str(page)]
else [#str(page) | _chapter one_ ]
let alignment = if calc.odd(page) { right } else { left }
align(alignment, body)
}
)
\
#set text(
font: "Lora",
size: 10pt
)
adding this to my template changes nothing:
set page(
header: [#set text(font: "Playpen Sans", size: 7pt)]
)
despite what the documentation shows for styling headers here
everything was actually working fine with this till I added a #pagebreak() in one of my chapters to force a section of images to move to the next page - the header on that page will only inherit the document font, and I don’t want to make a new chapter within a chapter.
To first explain your existing header styling code.
set text statements are limited by scope and only affect the part of the document that follows them in the same scope: For a one liner like the following, there is nothing following it, so the set text has no effect. Typst will tell you about this with a warning in a future version of Typst.
set page(
header: [#set text(font: "Playpen Sans", size: 7pt)]
)
Then apart from that, when you set page.header again, the two settings don’t concatenate or combine, the newest setting just overwrites, so it would also not have had effect for that reason.
I think typst is missing an easy way for templates to style page header without also defining their contents, so it’s a limitation you’ve run into.
I think you could solve it like this if you want to preserve a split between the template for style and document for content. The new function template-header needs to be defined in the template file:
#import "template.typ": *
#show: template
#set page(
header: context {
show: template-header
let page = counter(page).get().first()
let body = if calc.odd(page) [_title_ | #str(page)]
else [#str(page) | _chapter one_ ]
let alignment = if calc.odd(page) { right } else { left }
align(alignment, body)
}
)