003 / CLEAN ROOM · TYPESETTING CORE
Somadoc Next
A clean-room, Chinese-first typesetting engine, open source under Apache-2.0: parsing, line breaking, pagination, proofing and PDF export all run locally in the browser, with no request on the edit path.
STATUS OPEN SOURCE · APACHE 2.0
QUESTION
Can Chinese typesetting stop being a patch applied after the fact — punctuation, compression and line-edge trimming kept in a rules layer while the breaker sees only widths and boundaries, with the whole pipeline reproducible byte for byte across targets?
PRACTICE
Somadoc Next is a clean-room typesetting pipeline: no Typst, no TeX, no DOM, no platform font API. It reimplements the path from inline line breaking outward. It and Somadoc Engine are two answers to the same question — Engine keeps Typst as the typesetting core and owns parsing, the IR and output; Next replaces the core as well. Their code, licenses and numbers are not interchangeable.
The pipeline is single: each layer knows only the next contract. Two seams carry it. A rules layer turns Chinese into Atom and Boundary attributes; a metrics layer turns fonts into widths and ink. Line breaking and pagination read only those two layers, so each can be tested and replaced on its own. Three hard rules: the inline K-P kernel is frozen, the document IR carries no physical style, and templates carry no engine parameters.
Optimality is not measured against another engine. The cost is an additive, normalised sum of line count, badness, boundary deviation, trimming, short last line and height; brute force (n≤16) provides the reference, and K-P ≤ Greedy-C is a hard invariant. All geometry sits on a 1/4096 em integer grid: native, wasm32-wasip1 and the wasm32-unknown-unknown target in the browser emit the same canonical JSON with the same hash.
Since 2026-11-26 it also has a public browser entry: somadoc.art. soma-studio-core compiles parse to DocIR to template to layout to pages into one build function shared by the browser and Axum; soma-studio-ui links that whole chain plus the SVG and PDF renderers into wasm. The default deployment typesets, proofs and exports the PDF locally, with zero /api requests on the edit and export paths; the server keeps only file access, fonts and an optional native comparison (?server=1).
EVIDENCE
Atlas v1.1 (2026-11-26, main@c5948a1): 1,006 tests pass (one ignored), 120 ADRs, 28 crates and 92,527 lines of Rust. The 12 core gates are green, and the Studio S1–S10 + S12 pass on the public deployment (S2/S11 are server-side file-tree tests, skipped by design in the browser-local mode).
K-P measurements (local release, p95): pure Chinese 2,000 atoms 0.22 ms; punctuation-dense 0.53 ms; mixed 2,000 atoms 1.12 ms; mixed 4,000 atoms 2.26 ms — the slowest case uses 6% of the 20 ms / 80 ms budgets. D91 (mixed-script performance) is closed by the candidate window in ADR-0072; bench --check passes.
The Gate Q′ baseline is one CSV line: ALL,48,599,1213,0,0,3,0,0,6,809,1404,428,0 — 48 documents / 599 pages / 1,213 lines, zero over-compressed lines, zero emergency fallbacks, 3 continuation blocks, zero widows and zero orphans. The browser Studio does not enter that corpus path; it has its own S5/S12 hash and PDF checks.
The browser-local Studio, as measured on 2026-11-26: a 4,136,582 B wasm module (1,566,467 B gzip / 1,004,135 B brotli); GB2312 levels 1–2 fonts, 7,199 characters in five files (4.57 MB) shared by proofing and PDF; a local PDF of the welcome document in 224 KB and about 50 ms; a 7.5 MB tar / 16 MB unpacked deployment.
The samples are still one source plus one pure-YAML template: math-v2 at 2 pages, article 5, full 14, brief 12 and song 13, with the 3-page welcome.md as the default online document; PDF, HTML, SVG and canonical JSON share one LayoutResult. The boundaries are explicit: D119 stops browser fonts at GB2312 levels 1–2 (rare characters draw as empty boxes; the CLI keeps the full fonts), D104/D105 keep the build on the main thread with no single-file offline export, and D97/D98 leave math assembly and accent kerning open; there is no global book-level pagination, vertical writing, bidi, multi-column floats or whole-book incremental reflow. The source is public under Apache-2.0; the tests, gates and Studio numbers can be rerun from the repository and the public selftest.
RUST → WASM / NO TYPST · NO TEX / 1/4096 EM INTEGER / K-P + VERTICAL K-P / PDF · HTML · SVG · JSON
Try Soma Studio↗BROWSER-LOCAL / NO ACCOUNT
View the GitHub repository↗APACHE-2.0 / PUBLIC SOURCE / NO ACCOUNT
← Back to selected work→