Skip to main content

The pipeline

There are four commands. Three move a document forward; one inspects it.

collect resolve → expand → number → write stores
compile resolve → expand → paginate → emit static
render static source → layout → PDF
check parse → resolve → expand → number, writing nothing

The direction is one-way per run. Nothing in the pipeline runs backwards. Across runs, a document that prints a page count may need one extra pagination pass, which is measured and paid for rather than hidden.

What each command owns​

CommandOwnsWrites
collectNumbers. After expansion, before anything is laid out.One store per citable kind
compileLine breaking, page boundaries, floats, footnotes, lowering to static source.One static .mtx file
renderDrawing only: pages, lines, images, math, links and bookmarks.One PDF
checkReading and numbering, with provisional stores.Nothing

Order is not arbitrary:

  • Resolve before expand, because expansion is what consumes imports and props.
  • Number after expand, because the things being counted are instances, not tags in a file.
  • Paginate after number, so no number can depend on where lines land.
  • Render last, from a file that already contains every decision.

collect​

cargo mx collect paper.mtx

collect finds every <bib>, gathers the ids that can be pointed at, counts citable kinds in document order, and writes one module per kind into generated.dir (default gen/, relative to the config file):

gen/head.g.mtx type Heading + const headings
gen/fig.g.mtx type Figure + const figures
gen/tab.g.mtx type Table + const tables
gen/eq.g.mtx type Equation + const equations
gen/refs.g.mtx type Refs + const refs

A store is an ordinary module. It is written to be read by compile and by an editor, and it is meant to be committed — the union of ids is only useful if your tooling knows it before a build.

Stores are not checked for staleness

collect does not compare timestamps. If you have edited the document since the last collect, compile will read the old labels. Run collect before compile whenever numbers matter. A missing store, or an id that names nothing, is an error rather than a guess.

compile​

cargo mx compile paper.mtx -o build/paper.static.mtx

Without -o, the static file is written beside the input as <stem>.static.mtx.

compile resolves and expands the document, paginates it, and emits one static file. The file has:

  • no imports, components or declarations;
  • no flow and no <p>, <float>, <footnote>, <sup> or <sub>;
  • one <line> per broken line, with its space-before, height and any width/x positions already decided;
  • tables and formulas in their structural form, so render repeats the same arithmetic rather than reverse-engineering it;
  • every internal link still named by target id — destinations are resolved after drawing, which is why forward references need no second pass.

A short excerpt of real static source:

<page width={595.2756} height={841.8898} unit="pt"
margin={ { top: 73.7008, right: 68.0315, bottom: 68.0315, left: 68.0315 } }>
<footer>
<line unit="pt" align="center" space-before={0} height={8.8}>
<span font-size={8} unit="pt" font-family="body">1</span>
</line>
</footer>
<col>
<line unit="pt" align="left" space-before={28.3465} id="title" heading={1} height={19.8}>
<span font-size={18} unit="pt" font-family="body">Throughput</span>
…
</line>
<line unit="pt" align="justify" space-before={0} stretch={true} height={12.825}>
…
</line>
</col>
</page>

Read it top to bottom and you can see the page. That is the point of the intermediate form.

Images are referenced, not embedded

An imported image becomes a path in static source. <img> also accepts a data URI, and render will read either. A static file that points at image files is therefore not self-contained; move the assets with it.

render​

cargo mx render build/paper.static.mtx -o build/paper.pdf

Without -o, the PDF is written beside the static file, with .static.mtx replaced by .pdf.

render checks that its input is static before doing anything. A dynamic file is refused with not-static, and the message tells you to run compile first. It then lays the static source out and draws it. Internal <a to="…"> destinations are resolved after drawing, so a forward reference is fine.

check​

cargo mx check paper.mtx

check parses, resolves, expands and numbers, then reports. It writes nothing. It is the fast feedback loop: it catches a dangling link, an unknown prop, a missing store entry or a table that does not close before you pay for a render.

It prints ok when there are no diagnostics, and <n> warning(s) when there are only warnings. Errors exit non-zero.

Configuration​

Every command takes -c/--config <path> to use a specific project file instead of the nearest one. Without it, the engine walks up from the input document and uses the first matex.config.json or config.json it finds. With neither, the defaults apply.

Exit codes​

ResultExit code
Success, no diagnostics0
Success with warnings only0
Any error1

Warnings are not failures. A clipped float or a loose justified line is a fact about the document, not a reason to stop the build.

Invariants worth preserving​

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