Skip to main content

Module pageref

Module pageref 

Source
Expand description

Page-reference resolution and its layout fixpoint (issue #72).

@page(label) resolves to the printed page number of label’s target. Unlike a section or figure number, that page number is only known after layout, so it cannot be resolved in the single lowering pass: a page reference’s rendered width can shift pagination, which can move the target to a different page, which changes the number. The fixpoint drives layout repeatedly until the label→page map stabilizes.

Responsibilities are split by which input each step needs:

  • validate_page_references runs at lower time, where the label index exists, and reports an undeclared @page(x) as MOS0033, exactly like an undeclared @x. (It lives in resolve next to the index.)
  • resolve_page_references runs each fixpoint iteration with a label→page map from layout and rewrites each page reference’s text to the number.
  • resolve_page_reference_fixpoint is the driver. Layout is injected as a closure so this module keeps no mos-layout dependency (the one-way crate flow holds) and the loop is unit-testable with a mock layout.

Enums§

PageFixpointOutcome
The result of driving page references to a fixpoint.

Functions§

resolve_page_reference_fixpoint
Drive page-reference resolution to a fixpoint against an injected layout.
resolve_page_references
Rewrite every @page(label) reference’s visible text to its target’s page number, drawn from label_pages (a label→1-based-page map produced by layout). Returns whether any text changed, so the fixpoint driver can tell when the document settled.