Universe

Configurable figure numbering per section.

Examples

Basic

Have a look at the source here.

Example: basic

Two levels deep

Have a look at the source here.

Example: two levels deep

Usage

The package mainly consists of two customizable show rules, which set up all the numbering. There is also an additional function to make showing an outline of figures easier.

Because the show-figure() function must internally create another figure element, attached labels cannot directly be used for references. To circumvent this, a new label is attached to the internal figure, with the same name but prefixed with fig:, tbl:, or lst: for images (and all other types of generic figures), tables, and raw code figures (aka listings) respectively. These new labels can be used for referencing without problems.

// import the package
#import "@preview/i-figured:0.2.4"

// make sure you have some heading numbering set
#set heading(numbering: "1.")

// apply the show rules (these can be customized)
#show heading: i-figured.reset-counters
#show figure: i-figured.show-figure

// show an outline
#i-figured.outline()

= Hello World

#figure([hi], caption: [Bye World.]) <bye>

// when referencing, the label names must be prefixed with `fig:`, `tbl:`,
// or `lst:` depending on the figure kind.
@fig:bye displays the text "hi".

Reference

reset-counters

Reset all figure counters. To be used in a heading show rule like #show heading: i-figured.reset-counters.

#let reset-counters(
  it,
  level: 1,
  extra-kinds: (),
  equations: true,
  return-orig-heading: true,
) = { .. }

Arguments:

  • it: content — The heading element from the show rule.
  • level: int — At which heading level to reset the counters. A value of 2 will cause the counters to be reset at level two and level one headings.
  • extra-kinds: array of (str or function) — Additional custom figure kinds. If you have any figures with a kind other than image, table, or raw, you must add the kind here for its counter to be reset.
  • equations: bool — Whether the counter for math equations should be reset.
  • return-orig-heading: bool — Whether the original heading element should be included in the returned content. Set this to false if you manually want to construct a heading instead of using the default.

Returns: content — The unmodified heading.

show-figure

Show a figure with per-section numbering. To be used in a figure show rule like #show figure: i-figured.show-figure.

#let show-figure(
  it,
  level: 1,
  zero-fill: true,
  leading-zero: true,
  numbering: "1.1",
  extra-prefixes: (:),
  fallback-prefix: "fig:",
) = { .. }

Arguments:

  • it: content — The figure element from the show rule.
  • level: int — How many levels of the current heading counter should be added in front. Note that you can control this individually from the level parameter on reset-counters().
  • zero-fill: bool — If true and assuming a level of 2, a figure after a 1. heading but before a 1.1. heading will show 1.0.1 as numbering, else the middle zero is excluded. Note that if set to false, not all figure numberings are guaranteed to have the same length.
  • leading-zero: bool — Whether figures before the first top-level heading should have a leading 0. Note that if set to false, not all figure numberings are guaranteed to have the same length.
  • numbering: str or function — The actual numbering pattern to use for the figures.
  • extra-prefixes: dictionary of str to str pairs — Additional label prefixes. This can optionally be used to specify prefixes for custom figure kinds, otherwise they will also use the fallback prefix.
  • fallback-prefix: str — The label prefix to use for figure kinds which don’t have another prefix set.

Returns: content — The modified figure.

show-equation

Show a math equation with per-section numbering. To be used in a show rule like #show math.equation: i-figured.show-equation.

#let show-equation(
  it,
  level: 1,
  zero-fill: true,
  leading-zero: true,
  numbering: "(1.1)",
  prefix: "eqt:",
  only-labeled: false,
  unnumbered-label: "-",
) = { .. }

Arguments:

For the arguments level, zero-fill, leading-zero, and numbering refer to show-figure().

  • it: content — The equation element from the show rule.
  • prefix: str — The label prefix to use for all equations.
  • only-labeled: bool — Whether only equations with labels should be numbered.
  • unnumbered-label: str — A label to explicitly disable numbering for an equation.

Returns: content — The modified equation.

outline

Show the outline for a kind of figure. This is just the same as calling outline(target: figure.where(kind: i-figured._prefix + repr(target-kind)), ..), the function just exists for convenience and clarity.

#let outline(target-kind: image, title: [List of Figures], ..args) = { .. }

Arguments:

  • target-kind: str or function — Which kind of figure to list.
  • title: content or none — The title of the outline.
  • ..args — Other arguments to pass to the underlying outline() call.

Returns: content — The outline element.

Acknowledgements

The core code is based off code from @PgBiel (@PgSuper on Discord) and @aagolovanov (@aag. on Discord). Specifically from this message and the conversation around here.