#Is it really not possible to get the value of a counter as string without eval?
1 messages · Page 1 of 1 (latest)
I could answer it one way, but I think I need a bit more context as to what you are trying to do
?r ```typ
#set heading(numbering: (..nums) => {
let s = numbering("1.1", ..nums)
[#s (#type(s))]
})
= Foo
== Bar
here I answered it in that way anyway, but to prevent https://xyproblem.info, I would still recommend explaining the actual problem
If you want the value of a counter as a string don't you just use display, as in,
#counter(heading).display()
I’ll check your solution, currently busy. To clarify, I need to get the value of a counter and use it in the code, in the key of another counter. E.g. if heading counter value is 3 my customer counter should be keyed as “3-images-counter”.
This sounds like you actually want to use https://github.com/RubixDev/typst-i-figured
That will give you an opaque content instead of a string, which is often what you want, but not in this case
How about using locate as in:
let customer-counter() = {
locate(loc => {
let heading-counter-value = counter(heading).at(loc).first()
[#heading-counter-value] + [-images-counter]
}
}
The variable heading-counter-value is an Int (I believe). So you can use it however you wish inside that code block.