Ok I was talking BS, the order does matter for headcount. To fix your template, put the
show heading: reset-counter(counter(figure.where(kind: image)))
after all the other heading
show rules (in particular after your “custom heading design”).
If you’re interested, here is an explanation. The reset-counter
show rule is something like this
it => {
thecounter.update((0,))
it
}
where thecounter
is the counter in the argument, so in this case the counter of figure
. So it just resets the counter of figure
and then displays the heading as usual.
Now the question is, what happens if you put another show rule for heading below the one above. This will “wrap around” the show rule above, in the sense that it
in the new show rule is actually:
thecounter.update((0,))
heading(...)
So if you just reuse it
in your new show rule, everything will still be fine. For example, this still works:
#import "@preview/headcount:0.1.0": *
#set heading(numbering: "1.1")
#set figure(numbering: dependent-numbering("1.1"))
#show heading: reset-counter(counter(figure.where(kind: image)))
// custom design
#show heading: it => {
block(fill: green.lighten(20%), inset: 5pt, it)
}
= Introduction
#figure([some figure], caption: [some caption])
= Let's Go
#figure([another figure], caption: [another caption])
The problem now comes when, in your new show rules for your custom design, you do not use (the full) it
, but just for example it.body
. For example, this doesn’t work:
#import "@preview/headcount:0.1.0": *
#set heading(numbering: "1.1")
#set figure(numbering: dependent-numbering("1.1"))
#show heading: reset-counter(counter(figure.where(kind: image)))
// custom design
#show heading: it => [
#counter(heading).display() | #it.body
]
= Introduction
#figure([some figure], caption: [some caption])
= Let's Go
#figure([another figure], caption: [another caption])
The reason is that, because your don’t use it
as a whole, everything that’s done by previous show rules is not used, so you essentially discard all old show rules.
Putting the reset-counter(...)
show rule last fixes this, because then you first apply your custom design, and the reset-counter(...)
show rules then makes
thecounter.update((0,))
yourcustomdesign
out of this.
Just for completeness, let me mention that there is a second counter package with a totally different approach, which might be of interest to you to avoid such problems: rich-counters