Skip to main content

Architecture

The engine is one Rust crate, matex, behind a thin CLI. Everything is a stage with a named input and output; nothing reaches for a later stage's answer.

The pipeline​

resolve imports, components, props, consts, types
expand components → markup, props substituted, consts evaluated
number document order after expansion, demand-driven, per citable kind
paginate page boundaries, line breaking, tables, formulas, floats
emit dynamic markup → one static file
render static markup → display list → PDF
CommandRunsWrites
collectresolve → expand → numberStores
compileresolve → expand → paginate → emitOne static file
renderlayout → PDFOne PDF
checkresolve → expand → numberNothing

collect is not optional for anything that prints a number — it is what computes them — but it is a separate command: compile does not run it.

Why this order​

  • Resolve before expand, because expansion consumes imports and props.
  • Number after expand, because the things counted are instances, not tags in a file.
  • Paginate after number, so a number never depends on where a line lands.
  • Emit before render, so drawing has no decisions left to make.

The source model​

A .mtx file has a header of statements and then markup. Two shapes:

ShapeRootHolds
Document<doc>Markup, plus local declarations
ModulenoneImports, types, consts, components

Statements are imports, type declarations, const declarations and components. Each ends in ;. There is no token stream in the parser: markup and expressions switch too often for one to earn its keep, and a cursor over characters keeps spans exact.

Static source is defined by absence​

compile emits one file. What is missing from it is the definition:

  • no imports, components or declarations;
  • no flow;
  • no <p>, <float>, <footnote>, <sup> or <sub>;
  • no interpolations and no unparsed math.

Everything else is the same vocabulary. A static page is a <page> with geometry, a header, a footer and a <col> holding already-broken <line> elements plus the structural blocks that cannot be reduced to lines — rows, columns, tables, math and images. Each line has its space-before, height, optional width, and one <span> per run with an optional x. Tables and formulas keep their structure so render repeats the same arithmetic rather than reverse-engineering a picture.

That is what makes “render never invents a page” a structural claim rather than a promise.

Layout​

Layout produces a display list: pages, each with four slots — header, content, notes, footer.

Page
├─ header (line blocks)
├─ content (blocks: lines, rows, columns, tables, math, images, floats)
├─ notes (footnote paragraphs)
└─ footer (line blocks)

Blocks split by default. A break never falls inside a line, an image or a rule. A text block can refuse a break with keep; a heading always keeps with the lines that follow. The fragment minimum requires N lines on both sides of a break.

Pagination is iterative only when the document asks for it: pageCount() costs one extra pass because the total must be known before the second layout.

Numbers and references​

collect walks the expanded document in reading order and assigns numbers per citable kind. Numbering is demand-driven: a heading is numbered when {label()} appears in it, a figure or table when something reads its store entry's label, an equation when its row carries \label{…}.

The result is written as one module per kind:

type Heading = "intro" | "method";
export const headings = { "intro": { label: "1" }, "method": { label: "2" } };

Three properties follow:

  1. Type safety. A citation's to is a literal union of ids that exist.
  2. Inspectability. The numbers are a file you can read.
  3. Stability. Numbers are positional, so they survive a rebuild.

compile reads labels from the stores; it never counts a second time.

Style resolution​

One origin per property:

tag attribute → element.<tag> in config → engine default

There is no cascade, no selector and no inheritance from a container. An inline run inherits from the line it is part of because it is part of that line, not because a rule reached into it.

Crates and modules​

The workspace has two members. matex-cli is a thin shell over matex.

ModuleOwns
astSyntax tree: modules, types, components, expressions, markup
parserHand-written parser for both dialects
configProject file and its defaults
resolveLoading files and binding imported names
expandComponents, props, consts, expressions, demand tracking
numberLabels, store modules, document order
styleOne-level appearance resolution
fontOwned metrics, char-to-glyph map, named face set
imageFile paths and data URIs; PNG, JPEG, SVG, PDF/EPS rasterisation
textInline spans, greedy line breaking, hyphenation
mathSymbols, scripts, fractions, radicals, rows, cells
layoutPages, columns, tables, formulas, floats, targets
emitSerializing the static dialect
pdfPDF objects, embedded fonts, images, link annotations
errorProblems as data, with spans and stable codes

Invariants​

  • Nothing renders that was not resolved first; render accepts static source only.
  • render never invents a page.
  • A face is named by font-family; measurement and drawing use the resolved face, never a default silhouette.
  • A line is broken in compile, never at draw time.
  • One origin per property; no cascade and no selector.
  • Every loss is reported: clipped content is a warning, a missing glyph an error.
  • Numbers are computed once, by collect, and read from the stores by compile.

What exists, and what is designed​

The design record distinguishes three states, and the distinction matters when reading this site:

StateMeaning
BuiltIn the tree, exercised by the test suite
DecidedWritten down, agreed, not implemented
OpenA question with no answer yet

Class 1 is built. Class 2 and class 3 are designed. Some details inside class 1 — a repeated table header, running heads, footnotes — are built; others, such as a per-container keep, are not.

Status is the authoritative list.