FLM Feature flm.feature.numbering

Counter management and numbering for FLM document elements.

Provides counters for figures, equations, section headings, theorems, and other numbered elements. Supports hierarchical numbering (e.g. equations numbered within sections), counter aliases for shared numbering, and document-state-aware counter resets.

class flm.feature.numbering.Counter(counter_formatter, initial_value=0)

Bases: object

A basic counter that can be incremented, reset, and formatted using a CounterFormatter.

The counter holds an integer value starting at initial_value (default 0). Calling step() increments the value by one and returns the new value.

set_value(value)
step()
reset()
format_flm(value=None, **kwargs)
step_and_format_flm()
class flm.feature.numbering.CounterAlias(counter_formatter, alias_counter)

Bases: object

A counter proxy that delegates stepping and resetting to another Counter instance while using its own formatter.

This is useful when two different element types share the same underlying counter but need distinct display formatting.

property value
step()
reset()
format_flm(value=None, **kwargs)
step_and_format_flm()
flm.feature.numbering.get_document_render_counter(render_context, counter_name, counter_formatter, alias_counter=None, always_number_within=None)

Obtain or create a counter interface for the current render context.

When the numbering feature is enabled, the counter is registered through FeatureNumbering.RenderManager which supports hierarchical numbering and document-state resets. Otherwise a lightweight Counter (or CounterAlias) is created directly.

Parameters:
  • render_context – The active FLMRenderContext.

  • counter_name – A unique name identifying this counter (e.g. 'equation', 'section').

  • counter_formatter – A CounterFormatter for displaying counter values.

  • alias_counter – If provided, the returned counter shares its underlying value with alias_counter (a counter interface previously returned by this function or by RenderManager.register_counter).

  • always_number_within – A dict with keys 'reset_at' and 'numprefix' that forces hierarchical numbering. Requires the numbering feature; raises ValueError otherwise.

Returns:

A counter interface object with a register_item() method.

class flm.feature.numbering.FeatureNumbering(number_within: Mapping[str, TypeNumberWithinDef] | None = None)

Bases: Feature

Feature that manages counters for numbered document elements. Supports hierarchical numbering via number_within configuration, which resets and prefixes counters based on parent counter values (e.g. equations numbered within sections).

feature_name: str | None = 'numbering'

A name that should uniquely identify this feature.

feature_title: str | None = 'Numbering for figures, sections, equations, theorems, and more'

Descriptive name or title for this feature.

class RenderManager(feature_document_manager, render_context, **kwargs)

Bases: FeatureRenderManagerBase

initialize(number_within: Mapping[str, TypeNumberWithinDef] | None = None)
register_counter(counter_name, counter_formatter, *, alias_counter=None, always_number_within=None, use_doc_state_keys=None, numprefix_for_doc_state_fn=None, value_for_doc_state_fn=None)
compute_use_doc_state_keys(counter_name)
set_render_doc_state(state_type, state_value, clear_self_upon_change=None)
clear_render_doc_state(state_type)
register_item(counter_name, custom_label=None)
get_formatted_counter_value(counter_name, **kwargs)
flm.feature.numbering.FeatureClass = <class 'flm.feature.numbering.FeatureNumbering'>

Feature that manages counters for numbered document elements. Supports hierarchical numbering via number_within configuration, which resets and prefixes counters based on parent counter values (e.g. equations numbered within sections).