latex-macros
The groupant beside latex/src/macros.rs in the Mova repository: what the code computes, what it never does, how to go back from its outputs, its invariants, cost and checks.
Facts
Implementation material. A Mova code model describes this code at one source revision: partial models, finite checks and their stated scope. It is not a reviewed general exposition, and its labels are shown as written, never raised.
Components
| component | label | where |
|---|---|---|
| approximant | partial | approximant |
| ast | partial | syntax.json |
| composition | partial | composition |
| descriptant | present | descriptant |
| invariant | partial | invariant |
| tests | executed bounded checks | tests |
Obernants
The typed relations around the forward model: the behaviour complement (what the code never does), the reverse reconstruction (every input compatible with an output) and specialised views.
| id | type | label | where |
|---|---|---|---|
behavior_complement | behavior_complement | partial source derived model | behavior_complement |
reverse_reconstruction | reverse_reconstruction | partial source derived model | reverse_reconstruction |
overwrite_policy | overwrite_policy | partial source derived model | overwrite_policy |
capture_semantics | capture_semantics | partial source derived model | capture_semantics |
failure_precedence | failure_precedence | partial source derived model | failure_precedence |
delimiter_scope | delimiter_scope | partial source derived model | delimiter_scope |
Parts
Model text
descriptant
latex-macros
scan visits definition commands in token order, updates hash table on success, counts ignored provides as defined, counts malformed readers as skipped. let clones existing macro or captures CmdRaw. read_def validates body before sequential parameter numbers. match_pattern greedily consumes literal delimiters at brace depth zero.
Epoch2026-10-31: full source reviewed before edits; prospective models retained externally. No optimization.
approximant
Forward relation
scan visits definition commands in token order, updates hash table on success, counts ignored provides as defined, counts malformed readers as skipped. let clones existing macro or captures CmdRaw. read_def validates body before sequential parameter numbers. match_pattern greedily consumes literal delimiters at brace depth zero.
No useful approximate executable metric for exact categorical syntax; future caps1/2/5/10% only.
invariant
Domain, invariant and cost
scan visits definition commands in token order, updates hash table on success, counts ignored provides as defined, counts malformed readers as skipped. let clones existing macro or captures CmdRaw. read_def validates body before sequential parameter numbers. match_pattern greedily consumes literal delimiters at brace depth zero.
nargs accepted0..9 for newcommand; default read only when nargs>0. Malformed input consumed progressively. Source lifetimes own borrowed names/tokens.
O(B) lex plus definition bodies retained; expected hash lookup. Delimited scan O(T*L), where L delimiter length; cloning captured macros proportional to body/pattern/default sizes.
composition
Composition
scan visits definition commands in token order, updates hash table on success, counts ignored provides as defined, counts malformed readers as skipped. let clones existing macro or captures CmdRaw. read_def validates body before sequential parameter numbers. match_pattern greedily consumes literal delimiters at brace depth zero.
Build generates table enums consumed by parser dispatch and printers. Lexer tokens feed macros and parser; parser returns AST whose equality ignores spans. Printers and gate compare that quotient, not original bytes. Shared parent syntax backs scoped stages; stages are byte-bound projections, not independent Rust modules.
models
behavior_complement
providecommand cannot overwrite an existing definition. Failed pattern matching does not promise rollback. HashMap names does not promise sorted iteration.
reverse_reconstruction
Final macro table admits arbitrary overwritten definitions and ignored provides; scan stats constrain success/error counts but not unique source. let copy retains the captured old meaning despite later redefinition.
overwrite_policy
Later new/renew/def replace; provide only absent, but every successful read increments defined.
capture_semantics
let existing macro clones value; built-in target saved CmdRaw to avoid future expansion.
failure_precedence
read_def missing/unclosed body can precede out-of-order parameter diagnosis.
delimiter_scope
Delimiter matches only at zero brace depth; exactly one group loses braces.
tests
Evidence โ 2026-10-31
macros::tests::scans_definitions; macros::tests::delimited_def
Selected library filters ast:: lex:: macros:: parse:: print:: table:: and integration gate excluding document_extraction_with_preamble_macros and random_token_soup_never_panics_and_roundtrips. Direct rustc --test latex/build.rs exercises private helpers. All selected tests twice debug/release with identical sorted names. Four compiled mutants at build/AST/parser/printer boundaries fail assertions then exact restoration passes. These do not individually cover every source. Build-main failure effects, allocation failures and universal roundtrip are unproved. Strict Clippy reports existing lints. No corpus/live VMM/API/GPU/full-school/held-out tests.
This page in Markdown โ https://md.groupants.elamur.ai/free/en/mova/latex/src/macros.rs.groupant/