Hi,
like mentioned in the title, I want to store the value of a counter in a state. The ultimate goal is to achieve something like the exercism package does (but it does not correspond exactly and I don’t really understand the code).
I want that code
Thank’s @Mathemensch
It works with the example I gave, but in my real code both parameters of #q could be content, not just string. Then it’s not working. My bad.
For example
I think the issue here is that you store [#context mycounter.display()] in the state, which is then evaluated wherever the state is rendered – any snippet of content with a context inside of it gets that context rendered when it is placed in the final document. The solution here is to store the displayed counter itself:
#let q(a,b) = {
mycounter.step()
context {
let number = mycounter.display() // render with context of q function call
mystate.update(ans => {
ans.push([#number #b]) // store rendered number
ans
})
[#number #a \ ]
}
}