How to customize figure captions with subpar in 0.12?

I want figure captions with bold supplement+number+separator, but the following code does not seem to work well with the subpar package in the Typst 0.12 Testing version:

#import "@preview/subpar:0.1.1"

#show figure.caption: it => context box(
  inset: (left: 1em, right: 1em),
  align(left)[
    *#it.supplement~#it.counter.display()#it.separator*#it.body
  ]
)

#subpar.grid(
  figure(
    box(stroke: 1pt, inset: 5pt)[This is a figure],
    caption: [This is a caption]
  ),
  figure(
    box(stroke: 1pt, inset: 5pt)[This is a figure],
    caption: [This is a caption]
  ),
  columns: (1fr, 1fr),
  caption: [These are two subfigures.],
  placement: auto,
  label: <fig1>,
)

#figure(
  box(stroke: 1pt, inset: 5pt)[This is a figure],
  caption: [This is a caption]
) <fig2>

This is the result with 0.12 (the subpar figure has number 0):

image

This is the result with 0.11.1 (the subpar figure has number 1):

image

How to fix this?

Wait until @Tinger updates the package for v0.12 which hasn’t yet officially released. The issue is the new interaction between counter.display() and floating figures: How to customize the style of equation numbering? - #8 by xkevio

2 Likes

Thanks. Should I report the bugs I encounter in 0.12 directly as GitHub issues to avoid polluting the forum?

This you would have to report to the subpar repository as this new behavior isn’t actually a bug (in Typst) but technically correct now. The fact that counter.display() worked before with floating figures was apparently only a coincidence.

Yes of course, I meant filing an issue to the corresponding package.

1 Like

Indeed and that also gives us a hint at a solution. Because, this also reproduces the issue:

#show figure.caption: it => context box(
  inset: (left: 1em, right: 1em),
  align(left)[
    *#it.supplement~#it.counter.display()#it.separator*#it.body
  ]
)

#figure(
  box(stroke: 1pt, inset: 5pt)[This is a figure],
  caption: [This is a caption],
  placement: auto,
)

In both cases the solution is to nest the caption show rule inside a figure show rule and using that figure’s location to get the correct counter value, as seen here:

#show figure: fig => {
  show figure.caption: it => context box(
    inset: (left: 1em, right: 1em),
    align(left)[
      *#it.supplement~#numbering(it.numbering, ..it.counter.at(fig.location()))#it.separator*#it.body
    ]
  )

  fig
}

This fixes the issue for both cases, hope that helps. :)

1 Like

Let’s put it this way: Using the figure‘s location is definitely the most correct. The other thing working was more by accident than design. That said, its probably still the more desirable behavior. Having said that it is not a regression was sugarcoating on my end.

I’m still thinking through how exactly it should work, but it will probably change again, though I’m not sure whether in time for the release.