Skip to main content

Getting started

Requirements​

  • A Rust toolchain (stable) and Cargo.
  • A PDF viewer.
  • Optional: a .ttf or .otf face for real typography. Without one, the engine falls back to a bundled Liberation Sans face.

Build​

From the repository root:

cargo build

The binary lands at target/debug/matex-cli. The workspace also defines a shortcut:

cargo mx --help

cargo mx is an alias for cargo run -q -p matex-cli --, so every example below works with either spelling.

Your first page​

Create hello.mtx:

<doc>
<body>
<page flow>
<p>Hello, page.</p>
</page>
</body>
</doc>

Compile it to static source, then render the static file:

cargo mx compile hello.mtx -o hello.static.mtx
cargo mx render hello.static.mtx -o hello.pdf

compile reports the number of pages it produced. render writes the PDF. Open hello.pdf — one A4 page with 20 mm margins.

note

render refuses dynamic source with not-static. That is deliberate: layout is decided in compile, never at draw time.

Check without writing​

cargo mx check hello.mtx

check parses, resolves, expands and numbers the document without writing anything. It exits non-zero on errors, zero on warnings. It works before collect by treating generated stores as provisional.

Add a project file​

A project config is optional. It is found by walking up from the document, as either matex.config.json or config.json. Every key is optional.

config.json
{
"element": {
"page": { "size": "A4", "margin": { "top": 26, "right": 24, "bottom": 24, "left": 24 } },
"p": { "font-size": 10, "leading": 1.35, "align": "justify" },
"h1": { "font-size": 18, "leading": 1.1 }
},
"numbering": {
"h1": { "scope": "document" },
"h2": { "scope": "document" }
},
"font": {
"faces": [
{ "family": "body", "path": "assets/Inter-Regular.ttf" },
{ "family": "body", "path": "assets/Inter-Bold.ttf", "weight": 700 }
]
}
}

Paths in a config file are relative to that file, not to the working directory. A length is in millimetres unless the tag says otherwise; a font-size is in points.

tip

If font.faces is absent or a face cannot be read, the engine uses its bundled Liberation Sans face and reports a font-fallback warning. It never silently draws with the wrong family.

A document with real structure​

from "./cite.mtx" import component { Cite };

<doc>
<head>
<title>A short note</title>
<meta name="author" content="A. Saifudin" />
</head>
<body>
<page flow>
<header>
<p align="right" font-size={8}>A short note</p>
</header>
<footer>
<p align="center" font-size={8}>{pageNo()}</p>
</footer>

<col gap={4}>
<h1 id="intro">{label()} Introduction</h1>
<p>Layout is decided by structure, not by a stylesheet <Cite to="jin2026" />.</p>
<h2 id="method">{label()} Method</h2>
<p>The reference in <a to="intro">the opening</a> resolves after drawing.</p>
</col>
</page>
</body>
</doc>

The pieces at work:

  • <page flow> produces as many pages as the content needs. Without flow, it is a fixed page and overflow is clipped and reported.
  • <col gap={4}> stacks blocks with a 4 mm gap.
  • {label()} asks for the number of the heading it is written inside, so the heading is numbered. Omit it and the heading is not.
  • <header> and <footer> live in page slots; pageNo() is a core function.
  • <a to="intro"> is an internal link, resolved after drawing. <Cite> is an ordinary component, not a built-in tag.

Numbered references need collect​

Anything that reads a generated store — headings[id].label, figures[id].label, a citation — needs collect first:

cargo mx collect paper.mtx # writes one store per citable kind
cargo mx compile paper.mtx -o paper.static.mtx
cargo mx render paper.static.mtx -o paper.pdf

collect writes into generated.dir (default gen/), relative to the config file. The stores are ordinary .mtx modules and are meant to be committed: the editor needs the union of ids before a build.

Project layout​

A small project usually looks like this:

paper/
paper.mtx
config.json
cite.mtx
bibliography.mtx
assets/
Inter-Regular.ttf
plot.png
gen/
head.g.mtx
fig.g.mtx
tab.g.mtx
eq.g.mtx
refs.g.mtx

Where to go next​