Private betav0.3.0
DocsSign in
Format developer documentation

CounterDef

A counter declaration that optionally restarts under an owner counter.

A CounterDef declares one counter and, optionally, the counter it restarts under: a figure set to restart under chapter reads "Figure 2.1", returning to 0 at each new chapter. The default heading scheme is five of these, h2 through h6, each restarting under the level above; h1 never resets.

Fields

nameRequiredType stringThe counter this defines.
resetEachType stringThe owner counter this one restarts under, if any. Whenever the owner's value changes, on an advance, a set, or a reset, this counter returns to 0. The restart cascades, so every counter further down the chain returns to 0 too.

Example

A figure counter that restarts at each new chapter, so figures read 1.1, 1.2, then 2.1 in the next chapter. The h1 rule numbers the chapters in place of the default heading scheme.

<Numbering defaultHeadings={false}>
  <CounterDef name="figure" resetEach="chapter" />
  <NumberingRule match="h1" counter="chapter" format="Chapter {chapter}. " />
  <NumberingRule match="figure" counter="figure" format="Figure {chapter}.{figure}: " />
</Numbering>
<Numbering :default-headings="false">
  <CounterDef name="figure" reset-each="chapter" />
  <NumberingRule match="h1" counter="chapter" format="Chapter {chapter}. " />
  <NumberingRule match="figure" counter="figure" format="Figure {chapter}.{figure}: " />
</Numbering>
<template data-type="numbering" data-default-headings="false">
  <template data-type="counter-def" data-name="figure" data-reset-each="chapter"></template>
  <template data-type="numbering-rule" data-match="h1" data-counter="chapter" data-format="Chapter {chapter}. "></template>
  <template data-type="numbering-rule" data-match="figure" data-counter="figure" data-format="Figure {chapter}.{figure}: "></template>
</template>

Usage

A CounterDef names a counter and, with resetEach, the owner counter it restarts under. Whenever the owner's value changes, on an advance, a <Counter set>, or a <Counter reset>, this counter returns to 0, and that restart cascades on down to any counter that resets under it. You don't need a CounterDef to use a counter: a plain <Counter> works on its own and never restarts automatically, which suits a document-wide count like figures or steps. Add one only when you want a counter to restart under another. The default h1 through h6 heading scheme is built from CounterDefs, with h2 through h6 each restarting under the level above. Setting defaultHeadings to false on <Numbering> removes those CounterDefs along with the default heading rules.

Was this page helpful?