How to create a dynamic exercise bank?

read this post, it should help: Why is the value I receive from context always content?

in this case, you are wrapping the return value of current-chapter-title() in context, which means it can’t be read externally anymore. you should get rid of the context keyword for that function and just expect all callers (like problem) to have their own contexts instead. that way, everything is part of a single context block and the callers can read the value

#let current-chapter-title() = {

you should be able to apply this idea to your original custom implementation, in case you’re still interested in doing that (though i would simply use queries, not state). for example:

#let problem(body, sol) = body + [#metadata(sol) <sol>]
#let solutions() = context query(<sol>).map(meta => meta.value).join()

see how the context block is as “big” as we need it to be

1 Like