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):
This is the result with 0.11.1 (the subpar figure has number 1):
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.
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:
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.