engine — go-tex
-orange)
A pure-Go (no cgo) TeX engine, under construction — aimed at functional parity
with a TeX distribution, not a subset. This module is the engine's mouth and
gullet: a faithful re-implementation of TeX's category-code tokenizer, the
equivalents table (eqtb) with grouping/scoping, macro definition with
delimited parameters, and the full expansion machinery.
It is developed the way parity is actually reachable — reimplement the engine
faithfully, gated by TeX's own conformance oracle — and later run the real
LaTeX kernel and packages on it (they are TeX macros), diffing output against
pdftex/xetex. The primary gate here is the conformance ratchet
(TestConformance): TeX snippets checked byte-for-byte against real-TeX output.
Working today (verified, faithful)
- Category-code tokenizer — full catcode table, comments, control words/symbols.
- Macros —
\def (undelimited, delimited, and grouped parameters, with
backtracking on partial delimiter matches), \edef/\gdef/\xdef, \let
(to macros, primitives, undefined, and character tokens), \global.
- Expansion —
\expandafter, \csname/\endcsname, \noexpand, \string,
\the, \number, \romannumeral, \meaning, \uppercase/\lowercase.
- Conditionals —
\if, \ifnum, \ifx, \ifcat, \ifodd, \ifcase,
\iftrue/\iffalse, with \else/\or/\fi and nesting.
- Registers & arithmetic —
\count, \advance, \multiply, \chardef,
\catcode, read via \the/\count.
- Grouping —
{…}, \begingroup/\endgroup, save/restore of meanings,
registers, and catcodes; \global escapes the current group.
Faithfulness is checked on subtleties only real TeX gets right (a control word
absorbing its following space; significant spaces in conditional branches).
out, _ := engine.New().Run(`\def\twice#1{#1#1}\message{\twice{\twice A}}`)
// out == "AAAA"
Status & roadmap to parity
This is stage 1 (mouth + gullet). The remaining stages, each gated by an
objective oracle:
- ✅ Mouth + gullet — tokenizer,
eqtb, macros, expansion (this module).
- ⬜ Stomach — box/glue/penalty model, h/v lists, Knuth–Plass line
breaking, page builder,
\halign — gated by the TRIP test.
- ⬜ Math (Appendix G) —
go-tex/math is the starting point.
- ⬜ Fonts — TFM + OpenType (via
go-opentype).
- ⬜ Output — DVI → PDF (via
go-pdfkit), then run the real
latex.ltx + packages, gated by PDF-diff vs pdftex/xetex.
Because it is under construction, line coverage (currently ~84%) rises as
subsystems land; the meaningful gate is the growing conformance ratchet, not a
fixed coverage figure. Pure Go, CGO=0, go vet clean, green across six 64-bit
arches plus js/wasm and wasip1/wasm.
License
BSD-3-Clause — see LICENSE. Copyright the go-tex/engine authors.