How to add more fields to figure function?

Inspired by @quachpas’s solution and this post from @Andrew, figure can be redefined to include a custom field:

#show figure: set block(width:100%)
#show figure: set figure.caption(position: top)
#show figure.caption: it => align(left)[
  *#it.supplement
  #context it.counter.display(it.numbering)#it.separator*\
  #emph(it.body)
]
#let figure(note: none, body, ..args) = std.figure(..args, {
  body
  set text(size: 10pt)
  set align(left)
  [Source: ] + note
})

#figure(
  rect(width: 5cm, height: 5cm),
  caption: [A picture of a panda],
  note: [trust me], //<- custom field
)

I’ve replaced image(...) with rect() so the example would compile.

3 Likes