Do I need different code for numbering equations and figures?

Hey, I‘m trying to number my figures in such a way, that the first figure in section 1 is labeled 1.1, the second one 1.2, the first one in section 2 2.1, and so on. I have a piece of code that does exactly that for equations:


#set math.equation(numbering: it => {
    let count = counter(heading.where(level: 1)).at(here()).first()
    if count > 0 {
      numbering("(1.1)", count - 1, it)
    }
    else {
      numbering("(1.1)", count, it)
    }
})

The -1 is to adjust for my starting with section 0.

when adjusting to #set figure(numbering … , this doesn‘t work for figures. The first number changes correctly, but the second doesn‘t reset (yielding the number 2.4 for the first figure in section 2).
What am I missing? Thanks!

You need to also reset the figure/equation counters manually with each first-level heading. You can do so with a show rule

#show heading.where(level: 1): it => {
  counter(figure.where(kind: image)).update(0)
  counter(figure.where(kind: table)).update(0)
  counter(figure.where(kind: raw)).update(0)
  // ..repeat with whatever figure kinds you use
  counter(math.equation).update(0)
  it
}

Also, there is counter(..).get() which you can use instead of counter(..).at(here())

Ah, I see. Thanks for pointing this out!

Hello ,
So i just fiddle a little bit with this and

#set heading(numbering: "1.1.")
//This will reset counter at every heading level
#show heading: it => {
  counter(figure.where(kind: image)).update(0)
  //counter(figure.where(kind: table)).update(0)
  //counter(figure.where(kind: raw)).update(0)
  // ..repeat with whatever figure kinds you use
  //counter(math.equation).update(0)
  it
}

#set figure(numbering: it => { 
    let count = counter(heading).get()
    if count.len() > 1 {
      //I know my document will not have more than 3 level of headings
      numbering("1.1.A.", count.at(0), count.at(1), it)
      //e.g. This will put "Figure 2.3.A"
    }
    else {
      numbering("1.A.", count.at(0), it)
      //e.g. This will put "Figure 2.A" as the count will be only one level (main one)
    }
})



= Chapter name 
== Sub-chapter

#align(center+top)[
  #figure(
image("picture001.jpg", width: 25%),
caption: [this example graphic],

)<pictureA>
]

have a look at this Reference \@pictureA -> @pictureA

#align(center+top)[
  #figure(
image("picture001.jpg", width: 25%),
caption: [this example graphic],

)<pictureB>
]

= Chapter name 
#align(center+top)[
  #figure(
image("picture001.jpg", width: 25%),
caption: [this example graphic],

)<picture1.1.A>
]

#align(center+top)[
  #figure(
image("picture001.jpg", width: 25%),
caption: [this example graphic],

)<picture1.1.B>
]
#counter(heading).update(7)

== Sub-chapter


#align(center+top)[
  #figure(
image("picture001.jpg", width: 25%),
caption: [this example graphic],

)<picture2.1.A>
]
#align(center+top)[
  #figure(
image("picture001.jpg", width: 25%),
caption: [this example graphic],

)<picture2.1.B>
]

Hope this helps

Thank you, this helps a lot, especially since I‘m pretty new to typst and still trying to get the hang of it.