#Is it really not possible to get the value of a counter as string without eval?

1 messages · Page 1 of 1 (latest)

jovial veldt
#

.

violet crest
#

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

violet crest
#

here I answered it in that way anyway, but to prevent https://xyproblem.info, I would still recommend explaining the actual problem

wet minnow
#

If you want the value of a counter as a string don't you just use display, as in,

#counter(heading).display()
jovial veldt
#

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”.

violet crest
violet crest
wet minnow
#

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.