go-typeset

Typesetting, not typography. Where the marks go, not what they look like.

go-typeset holds the algorithms that decide where text goes: Knuth–Plass optimal line breaking, Liang hyphenation, and the Unicode bidirectional algorithm. Pure Go, cgo-free, standard library only, 100% test coverage.

They came out of the go-tex engine, where they were already written as self-contained algorithms with no reference to engine state — so extracting them was a move, not a rewrite. Their public API carries no TeX vocabulary, because a paragraph breaker is not a TeX component.

Pure Go CGO=0 Standard library only 100% coverage 6 architectures BSD-3-Clause

Why go-typeset

Breaking a paragraph into lines well is not a TeX feature — it is an algorithm, published in 1981, that any renderer of text wants: a PDF writer, an e-book engine, a terminal formatter, a widget toolkit. The same is true of hyphenation and of the bidirectional algorithm. Inside a TeX engine they are invisible to everyone else; on their own they are reusable.

So they were lifted out of go-tex — a move, not a rewrite, because they were already written as pure algorithms with no reference to engine state. Their API deliberately carries no TeX vocabulary. The engine now consumes them like any other caller, through a small aliasing seam, and its own code reads unchanged.

Packages

Three modules, each usable alone, each with no dependencies beyond the standard library.

linebreak

Knuth–Plass optimal line breaking: the box / glue / penalty model and the paragraph builder. Breaks are chosen for the paragraph as a whole rather than line by line, which is what gives TeX its even greyness.

hyphenation

Liang's algorithm, reading TeX's own pattern files. Honours \lefthyphenmin/\righthyphenmin, and documents — with a test pinning it — the one place it diverges from the thesis.

bidi

The Unicode bidirectional algorithm: embedding levels and visual reordering for mixed left-to-right and right-to-left text.

Quality bar

100% statement coverage on every module, error branches included, on six 64-bit architectures, three operating systems and both wasm targets. No cgo, no third-party dependency, BSD-3-Clause.

Two API additions were forced by wiring the engine back onto the extracted libraries — a last-resort tolerance, and the hyphenation minima. That is the useful signal that the extraction was real: an algorithm sealed inside its only caller never has to expose its parameters.