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.
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.
If you don’t want to use the heading elements, you can define some custom ones for your needs. The key is to define a way for Hydra to display the custom element.
hydra is built with custom elements in mind. Some documents may use other elements for chapters or section-like content. hydra allows defining its own selectors for tight control over how elements are queried.
Hmm. I forgot there’s more data I wanted to attach to each exercise. I settled on the exercises being content with a label, and metadata which is attached to it which is… a dictionary as a str, later evaluated to its “contents” using eval.
In addition to Hydra, it works. Pretty much. That’d be a hybrid of your suggestions and the cursed use of eval.
To that add a correct use of header setting (finally!) , so there won’t be a header in the title page, while the rest of the document won’t act up.
Typst is so powerful and I love it, but man, it’s just so overly complicated sometimes, and I haven’t tried studying the Rust API…