Counter
An inline counter, read or advanced by hand, whose value survives pagination.
A Counter is an inline running number you place by hand. It reads or advances a named counter and prints the value where it sits; counters share state by name across the document, so a rule and a Counter that name the same counter stay in step.
Give a Counter an id to make the value it prints a Ref target.
Fields
| Name | Type | Description |
|---|---|---|
nameRequired | string | The counter to read or advance. Shared by name across the document. |
action | CounterAction | What to do with the counter. Defaults to next. |
value | integer | The step for next, or the exact value for set and reset. |
join | string | When set, read the whole nested chain joined by this separator (the counters() read) rather than the innermost value alone. |
counterStyle | string | The counter style to format the value in. Defaults to the document's numbering style, or decimal. |
Example
A figure caption that advances the shared figure counter and prints its value.
<figure id="fig-flow">
<figcaption>Figure <Counter name="figure" />: the numbering pass</figcaption>
</figure><figure id="fig-flow">
<figcaption>Figure <Counter name="figure" />: the numbering pass</figcaption>
</figure><figure id="fig-flow">
<figcaption>Figure <span data-type="counter" data-name="figure" data-action="next"></span>: the numbering pass</figcaption>
</figure>Usage
A Counter shares state by name across the whole document, so a rule and a Counter that name the same counter stay in step. You don't declare a counter first: the first <Counter> to name it starts at 1, and every Counter or rule with that name continues the same count. Add a <CounterDef> only when you want a counter to restart under another, like figures numbered per chapter.
By default it advances the count and shows the new value; peek reads without advancing, set jumps to a value, and reset starts over. These three are mutually exclusive, and when more than one is set, reset wins, then set, then peek. To read a nested chain as 1.2.1, pass join=".".
Give a Counter an id to make its printed value a <Ref> target, the same way a heading's id yields its section number.