I’ve been trying to create a template for homework (math problems in particular, but could easily be expanded) which has an “exercise” function, and which shows the current (last as of the current page) exercise in the page’s header. The way I chose for doing this is to create an “exercises” state (which I’m not a fan of, as it exists outside of the main template function), update it with every call of the “exercise” function, and display the “last” one in the header.
The problem is, I’ve found out the header’s content seems to “evaluate” before any of the page itself does. In contrast, the footer seems to update after. So the template works as intended - always one page behind.
Consider the following example:
#let arr = state("arr", ())
#set page(
header: [
arr:
#context arr.get()
#line(length: 100%)
],
footer: [
arr:
#context arr.get()
#line(length: 100%)
]
)
#arr.update("Hey!")
Which renders as
while I want the header to look like the footer.
Anyone has any idea on how to solve this? Or alternatively, a better way to do what I want? Initially I tried using labels, but working with content is a nightmare. I do not know how the rendering in Typst actually works, so this problem may be deeper than it seems.
