How to avoid numbering subfigure captions when using legal numbering?

The problem

I have a document where I need (1) legal numbering and (2) a figure with subfigures. Legal numbering in this context means that paragraph in the main text are numbered, but not other paragraph-like entities, such as footnotes or captions.

I’ve set up the paragraph numbering using this show rule for pars. It works quite and well and the document still compiles quickly, which is great.

The one issue I’m running into is that subpar figures add paragraph numbering to the subfigure captions (though not the normal superfigure caption). Standard figures #figure(...) do not have paragraph numbering.

Is there something obvious I’m missing?

Some things I’ve considered

  1. Writing a new show rule on par within the subfigures, but this seems to not converge show par: it => it.body
  2. Using a state within a show rule for subfigures and checking that state, but this gives only element functions can be used as selectors
    These were variants of setting a state say do_count and adding to the show par:
    context {
      if do_count.get() == 0 {
        return it
      }
    }

and to the super:

  #show subpar.super: it => {
    do_count.update(0)
    it
    do_count.update(1)
  }

reprex

#import "@preview/subpar:0.2.2"

#set page(height: auto)
#set par(justify: true)

#let cnt_para = counter("para")
#let step = cnt_para.step()
#let n_para = context cnt_para.display()
#show par: it => {
    if it.body.at("children", default: ()).at(0, default: none) == step {
      return it
    }
    par(step + [#n_para. ] + it.body)
}

= Some header

And then there's text, followed by our test figure.

#subpar.super(
grid(
[#figure(rect(fill:red), caption: [An image]) <fig1a>],
[#figure(rect(fill:blue), caption: [Another image]) <fig1b>],
figure(rect(fill:yellow), caption: [A third unlabeled image]),
columns: (1fr,) * 3,
),
caption: [A figure composed of three sub figures.],
label: <fig1>,
)

But note that a regular figure does not have this issue:

#figure(rect(fill:red), caption: [An image]) <fig2>

The doc ends with a little more text.

Forgot to add, it seems to be related to this show rule

show figure.caption: it => {
   num
   [ ]
   it.body
}

where editing the caption no longer has a caption object, so it gets the par rules.

This show rule is incorrect. It misses block wrapper, which makes it a paragraph.

Thanks @Andrew. Appreciate it. That works well.

(For anyone in the future, this means that setting:

show figure.caption: it => block({
   num
   [ ]
   it.body
})

avoids the return as a par.)

1 Like

I made a patch: Fix figure caption show rule by Andrew15-5 · Pull Request #40 · tingerrr/subpar · GitHub. If a new version is released fast, then the fix can be available on Monday. But that’s a big if.

2 Likes