How to customize figure reference with panel letter?

I have a figure with multiple panels A-D. In text I would like to reference single panels of this figure. I am aware, that typst won’t be able to reference the panels by itself, so I was wondering if there is a way to add the panel label to the figure reference. Something like: typ #ref(<Figure1>, panel = "A") , which would then result in Figure 1.A

The cases I tried so far are:

@Figure1 // The normal case
@Figure1 .A // This results into a space between the ref and .A
#link(<Figure1>)[Figure 1.A] // This has the desired result, however, the downside is that the label number would not get updated if I add another figure

Anyone has an idea? I would appreciate the help.

You might be interested in this package subpar – Typst Universe (shoutout to @Tinger!).

If your figure contains a single image with no referenceable content, I am afraid your only solution remains manually writing the panels. If your issue was with how to reference the figure’s number, it is solved by calling the function ref.

EDIT: thanks @flokl, your solution is much better.

#let lk(lab, suffix) = {
  return {
    link(lab)[#ref(lab).#suffix]
  }
}
#lk(<full>, "A")

See below for subfigures with subpar’s package.

#import "@preview/subpar:0.1.1"

#subpar.grid(
  figure(rect(fill: red), caption: [
    red block
  ]), <a>,
  figure(rect(fill: blue), caption: [
    blue block
  ]), <b>,
  columns: (1fr, 1fr),
  caption: [A figure composed of two sub figures.],
  label: <full>,
)

Above in @full, we see a figure which is composed of two other figures, namely @a and @b.

1 Like

I think @Rene_Skuk has a single picture with A-D. You can escape the .A part with a backslash like this: @figure-label\.A, which results in Figure 1.A

1 Like

Yes, that’s what I was looking for. Thanks @flokl