#set page(
header: context {
let page = here().page()
let is-start-chapter = query(heading.where(level: 1))
.map(it => it.location().page())
.contains(page)
if not state("content.switch", false).get() and not is-start-chapter {
return
}
state("content.pages", (0,)).update(it => {
it.push(page)
return it
})
},
footer: context {
let has-content = state("content.pages", (0,))
.get()
.contains(here().page())
if has-content {
align(center, counter(page).display())
}
},
)
The combination of the three causes the layout not to converge within 5 attempts, locally I have recompiled Typst with the limit lifted so I know there are no deadlocks, it’s just a lot of context but I not sure what to do about it. Thank you in advance!
Layout not converging fast enough is always tricky
In your case, I would try if it helps to remove the header stuff – as far as I can tell could you check for headings and state("content.switch") in the footer, and get rid of state("content.pages")
In my experience having such “dependecy chains” of state/context is usually the problem (your content.pages state depends on content.switch, query.heading and here.page())
It might also be worth it to include a .before(here()) in your selector (after moving it to the footer), which would allow you to only consider the .last() heading found.
I had tried before to remove the header context but didn’t really succeed, could you show me exactly what you mean? I’m not 100% confident that I get it
Oh I get it now, that makes sense, thank you! It doesn’t fix the problem completely, even without it it doesn’t converge in 5 iterations, but it certainly is a start