I’m designing a document with multiple “chapters”; specifically, it’s a journal. Each chapter is a different article with a different author and so on. I’m using H1 as the chapter / article title.
Each article section (as well as the foreword) should have a specific footer on the first page, and then the rest of the pages have a footer that alternates whether it’s a recto or verso page.
The relevant footer code is the following:
// footer of first page of each "section" has journal metadata
#let section_firstpage_footer = context [
#meta.journal, #meta.volume, #meta.date.display("[month repr:long] [year]")
#h(1fr)
#counter(page).display()
]
// footer of rest of article has article metadata
#let article_body_footer(article) = context {
if calc.even(counter(page).get().first()) [
// if verso, numbers outside and title inside
#counter(page).display()
#h(1fr)
#if article.keys().contains("short_title") [
#article.short_title
] else [
#article.title.split(":").first()
]
] else [
// if recto, author inside and numbers outside
#text(style: "italic", article.author)
#h(1fr)
#counter(page).display()
]
}
// journal metadata on first page of section, article metadata on rest
#let article_footer(article) = context {
// if page has h1, it means it's the first page of a section
let is_section_first_page = query(heading.where(level: 1)).any(m =>
counter(page).at(m.location()) == counter(page).get()
)
if is_section_first_page {
section_firstpage_footer
} else {
article_body_footer(article)
}
}
And it’s used like so:
// foreword
#pagebreak(weak: true, to: "odd")
#page(
footer: article_footer(meta.foreword),
[ // ...
]
)
But on the recto pages of the article body, it shows the first page footer:
Except it works for the second article:
I made an example document in the web-app to share.
I started with Typst yesterday so I think I may be missing some things. Is there something wrong with doing this?
#let is_section_first_page = query(heading.where(level: 1)).any(m =>
counter(page).at(m.location()) == counter(page).get()
)
Or is it something about context
that I’m missing? I suspect it’s that.
If anyone has any general comments about the best way to structure a multi-section document or something else about how I’ve done things, please feel free to let me know as well (e.g., my next mission is to include the author names in the table of contents).
I feel like I’m missing an abstraction like chapter
and part
in Latex, or section as in MS Word, or even something as abstract as a div
which I can target with CSS. I’ve been using #page
to encapsulate sections (since they conveniently automatically overflow onto multiple pages), but in the article sections I need to start a new page to have the two-column layout (or should I manually do a page break and call #columns
inside the page content? — Edit: I did this, for conistency), so I’m also relying H1s to indicate the start of a section, but then I have to strip off the first part of the section numbering so it doesn’t include a chapter number that I don’t use and that I have to manually increment as well… It feels like I’m doing something wrong. What’s the “native” way that Typst understands sections? Is it basically just following H1s?