How to get the effective heading number from a heading object?

I have a function that gets passed labels as strings. From these labels I query the associated heading. From this heading object, I can get some properties, such as the body, numbering, etc.

#set heading(numbering: "1.")
#let heading-label-as-str = "heading-B1b"
#let f(l) = context {
  let h = query(heading.where(label: label(l))).last()
  [
    The number of heading "#l" is "2.1.2" 
    and not #h.numbering, #h.level, or #h.depth
  ]
}

= A
= B
== B1
=== B1a
=== B1b <heading-B1b>

#f(heading-label-as-str)

How can I get the effective heading number from it? (“2.1.2” in the example)

The heading number is accessed through the counter, so in your example:

#let f(l) = context {
  let h = query(heading.where(label: label(l))).last()
  let counter-value = counter(heading).at(label(l))
  let displayed-number = numbering(h.numbering, ..counter-value)
  [
    The number of heading "#l" is #displayed-number
  ]
}
1 Like