How to fix counter display and locate functions in Typst v0.13?

Hello everyone,

I’m encountering some issues with my code after updating to Typst version 0.13. Previously, everything worked fine, although about a month ago I started receiving a warning related to the ap.display("a)") and loc function. Now, in v0.13, that part of the code doesn’t work at all.

Here is a part of the entire code

#let c = counter("exercise")

#let ap = counter("section")

#let tag-filter = state("tag-filter", _tag => true)


#let exercise(
  tag: none,
  body,
) = locate(loc => {
  if not tag-filter.at(loc)(tag) {
    return
  }
  c.step()
  block(width: 100%, below: 1.6em,
    box(width: 12.6pt,
      c.display("1."))+body
  )
})


#let secq(
  scoring: 1,
  tdah: false,
  body,
) = {
  block(width: 100%,
    if scoring == 1 {
      ap.step()
      box(width: 100%,inset: (left:16pt), ap.display("a)")+[ (#scoring punto) ]+body)
    } else {
      ap.step()
      box(width: 100%,inset: (left:16pt), ap.display("a)")+[ (#scoring puntos) ]+body)
    }
  )
  if tdah {v(15pt)}
}

Could someone clarify what changes have been made regarding ap.display and the behavior of the loc function in the latest version? I’m looking for guidance on how to properly update my code.

Thank you for your help!

@quachpas wrote a very detailed answer about locate: How to use context instead of a callback function in locate function calls? - #2 by quachpas

.display(...) is contextual and needs to be called with the context keyword: context ap.display("a)")

2 Likes

Thank you so much for your help! The example in the thread was exactly what I needed to understand the changes and update my code accordingly. I really appreciate your clear explanation and support.