How to create 2nd level numbering for figures?

Hey,
I have a problem with multi level numbering in figures. This is what the result should look like.

  • 1
  • 2.a
  • 2.b
  • 3

Here is my current code:

// normally step on level 1
#show figure : it => {
  counter("fig").step(level: 1)
  context {
    let numb = numbering("1.a",..counter("fig").get())
    set figure(numbering: n => numb)
    context it // here the set rule from above should apply 
  }
}


// if in subBlock step on level 2
#let subFigs(doc) = {
  counter("fig").step(level: 1)

  show figure : it => {
    counter("fig").step(level: 2)
    context {
      let numb = numbering("1.a",..counter("fig").get())
      set figure(numbering: n => numb)
      context it // here is the same problem
    }
  }

  doc
}

#figure(image("meme.jpg", width: 50%),
  caption: [First meme],
)

#[
  #show: subFigs

  #context figure(image("meme.jpg", width: 50%),
    caption: [Second (2.a) meme],
  )

  #context figure(image("meme.jpg", width: 50%),
    caption: [Second(2.b) meme],
  ) <sub2>
]

#figure(image("meme.jpg", width: 50%),
  caption: [Third meme],
)

If there is a more elegant way to make this work, please let me know.

I use my own counter because I found no way to stop the figure function from stepping the figure-counter on level 1.

Currently the main problem is that the set rule does not apply to the row below it. I have no idea why…

Thank you for your support :)

Hey. Your code does not compile. See https://sscce.org. Usually for figures you can use [] or rect().

#import "@preview/subpar:0.2.2"

#figure(rect(), caption: "First")

#subpar.grid(
  figure(rect(), caption: [Second a]),
  figure(rect(), caption: [Second b]),
  numbering-sub: "(1.a)",
  show-sub-caption: (num, it) => [#it.supplement #num#it.separator #it.body],
)

#figure(rect(), caption: "Third")