Modules, types and components
A .mtx file has two regions: a header of statements, then markup. A file
whose root is <doc> is a document; a file with no root is a module. Both may
hold imports, types, consts and components.
from "./cite.mtx" import component { Cite };
from "./ui/types.mtx" import type { Align };
from "./assets/plot.png" import plot;
export type Placement = "top" | "bottom";
export component Figure {
prop id: string;
prop src: image;
prop width: string;
prop alt: string = "";
prop placement: Placement = "top";
prop children: markup;
return (
<div id={id} keep>
<img src={src} width={width} alt={alt} />
<caption labelled-by={id}>{children}</caption>
</div>
);
}
Imports
Path first, so completion can start at the path:
from "./sections/chapter1.mtx" import component { Chapter1 };
from "./ui/types.mtx" import type { Align };
from "./refs/configs.mtx" import const { compact };
from "./assets/plot.png" import plot;
| Form | Takes |
|---|---|
import component { X } | One or more exported components |
import type { T } | One or more exported types |
import const { c } | One or more exported constants |
import value | A file that is one value, such as an image |
One kind per statement, never mixed. The four forms parse with one keyword of
lookahead, which is what lets an editor know what to suggest after import.
Paths are relative to the importing file. The core functions are available
without an import; from "core" import { pageNo } is also accepted.
Types
Deliberately small, and no generics:
export type Align = "left" | "center" | "right";
export type Column = { span: number, width?: string };
export type Columns = Column[];
export type Maybe = { value: string, note?: string };
| Type | Meaning |
|---|---|
string, number, bool | Primitives |
image | A value from an image import |
markup | A value from a <fragment> |
| `"a" | "b"` |
{ field: T, optional?: T } | An object type |
T[] | An array of a named or primitive type |
An unexported declaration is private to its module.
Constants
Module-level values with an optional declared type:
export const compact: Column[] = [ { span: 6 }, { span: 6 } ];
This is how appearance is shared without a cascade: the style is a value you pass, not a rule that reaches into other elements.
<DataTable config={compact} />
A const may also appear inside a component body, evaluated at expansion:
const record = refs[to];
return <a to={to}>{record.short}</a>;
Components
A component is a declaration, not a file root. A file may hold several, and they are private unless exported.
A body has three parts, in order:
propdeclarations, with optional defaults;conststatements andifstatements;returnon every path.
export component CiteEq {
prop to: Equation;
const eq = equations[to];
return <a to={to}>Equation ({eq.label})</a>;
}
export component RunningHead {
prop title: string;
if (isEven(pageNo())) {
return <p align="right" font-size={8}>{title}</p>;
}
return <p align="right" font-size={8}>{title} — odd</p>;
}
Parentheses may wrap the returned markup when it spans several lines. The
statement still ends with ;.
children is a prop
Content is not a special channel. A component that takes content declares it:
export component Note {
prop kind: "info" | "warning";
prop children: markup;
return <p>{children}</p>;
}
<Note kind="warning">This is the body.</Note>
A component only receives content when it declares prop children: markup. <fragment>…</fragment> makes markup a value, so markup can be passed as a prop:
<DataTable caption={<fragment>…<math>T_{\mathrm{cp}}</math>…</fragment>} />
Calls
<Figure id="fig-1" src={plot} width={86}>Throughput against SNR.</Figure>
<Cite to="jin2026" />
- A required prop that is missing is an error (
missing-prop). - A prop the component does not declare is an error (
unknown-prop). - A value of the wrong type is an error (
type). - Recursion is bounded at 64 nested instances (
recursion).
A component that forwards an id should put it on an element it generates, or
pointers to it dangle. Nothing currently enforces that; it is a contract.
Expressions
An attribute value is an expression. A quoted string is a string literal.
align="right" // string
columns={12} // number
src={plot} // identifier
config={compact} // identifier
defaults={ { align: "right" } } // object literal
spans={ [ { span: 4 }, { span: 3 } ] }// array literal
columns={config.grid} // field access
equations[to] // indexing
The boundary is deliberate: literals, identifiers, object and array literals,
field access, indexing, and calls to core functions. No arithmetic and no
author-defined functions. {10 + 2} is not an expression; write {12}.
Interpolation uses the same expressions:
<p>Section {headings[to].label} begins here.</p>
Core functions
| Function | Available | Returns |
|---|---|---|
pageNo() | In a header or footer | Current page number |
pageCount() | In a header or footer | Total pages (costs one extra pass) |
isEven(n), isOdd(n) | Anywhere | A bool |
isPage(n) | In a header or footer | Whether this is page n |
label() | Inside a heading | That heading's number |
pageNo, pageCount and isPage are available in a page's header or footer,
which are expanded while the page is laid out. They are not available in the
page body, which is expanded before layout; using them there is an error
(page-no-outside-page, page-count-outside-page).
label() outside a heading is an error (label-outside-element or
label-not-heading).
Comments
// to the end of the line, and /* … */, are comments wherever whitespace is
allowed: between statements, attributes and nodes.
They are not recognized inside text, strings or raw math, so
https://example.org in prose stays text and a // inside $…$ is math.
What a module is for
A module is how a project shares things: a type used by several documents, a caption component, a style constant, a bibliography. It is the same file format as a document, with the root omitted.