Add the M1 box/glue/penalty paragraph builder

This commit is contained in:
gloamxun committed 2026-10-20 12:11:09 +08:00
1 parent 99dbb5ebb0
commit 51beb682f0
5 files changed
+282 -30

No files matched your search

+30 -11
View File
@@ -1,6 +1,6 @@
# TeX-compatible incremental core (route D)
Status: **M0 architecture spike implemented** in `crates/texrra-tex-core`.
Status: **M0 architecture spike + M1 paragraph builder implemented** in `crates/texrra-tex-core`.
The production v1 engine in `src/rust_typeset` remains the default and is kept as
a fallback while the TeX-compatible core grows.
@@ -21,7 +21,7 @@ operation from the start. It does **not** embed pdfTeX, XeTeX or Tectonic.
- `VerticalItem::{Box, Glue, Penalty}` and `VerticalBox` as the first vertical
list model;
- `Unit::paragraph` as a placeholder for the future TeX paragraph builder;
- `Unit::paragraph` backed by the M1 box/glue/penalty paragraph builder;
- `Engine::layout` that builds pages with a simple page goal;
- `Checkpoint` before every top-level unit, containing the completed-page count,
used vertical space and current page items;
@@ -32,8 +32,26 @@ operation from the start. It does **not** embed pdfTeX, XeTeX or Tectonic.
`recomputed_pages`;
- serde round-trip for checkpoints.
M0 proves the incremental contract, not TeX compatibility. The paragraph
builder, page builder, math, fonts and class execution are still ahead.
M0 proves the incremental contract; M1 starts replacing the placeholder with
horizontal material and a paragraph breaker. The page builder, math, fonts and
class execution are still ahead.
## M1 scope (paragraph builder)
`crates/texrra-tex-core/src/paragraph.rs` adds:
- `HorizontalItem::{Box, Glue, Penalty}` and `HorizontalBox` as the horizontal
list model;
- `ParagraphStyle` with `line_width`, `par_indent`, `line_height`, fixed
character/space metrics and glue stretch/shrink;
- a word-level Knuth-Plass-style dynamic program that minimizes badness from
glue stretch/shrink, allows overfull lines with an explicit overfull penalty,
applies `par_indent` to the first line, and emits justified glue;
- `Paragraph { lines, height, width }` and a paragraph-backed `Unit`.
M1 is deliberately word-level: it does not yet hyphenate, process
`\discretionary`, use real TFM metrics or compare against pdfTeX. Those are the
next paragraph milestones.
## Target architecture
@@ -50,7 +68,7 @@ builder, page builder, math, fonts and class execution are still ahead.
| Milestone | Content | Acceptance |
| --- | --- | --- |
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 |
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | line breaks match pdfTeX for test paragraphs |
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item model + word-level breaker implemented; hyphenation/TFM/pdfTeX parity next |
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | one-column article matches reference pages |
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | table width/rules match reference |
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | arXiv formulas render without overlap |
@@ -60,10 +78,10 @@ builder, page builder, math, fonts and class execution are still ahead.
## Current limits
- The M0 paragraph model is a character-count placeholder; it does not run the
TeX paragraph algorithm yet.
- Page breaking only handles vertical boxes/glue; penalties are recorded but not
interpreted.
- The M1 paragraph builder is word-level with fixed metrics; it does not yet
hyphenate, honor all penalties, or use TFM font metrics.
- Page breaking only handles vertical boxes/glue; vertical penalties are recorded
but not interpreted.
- No macro state, output routine, math, fonts or PDF output in the new core yet.
- The v1 server and project API still use `src/rust_typeset` and are unchanged.
@@ -73,5 +91,6 @@ builder, page builder, math, fonts and class execution are still ahead.
cargo test -p texrra-tex-core --offline
```
The four M0 tests cover page splitting, checkpoint serialization and
page-local editing.
The M0 tests cover page splitting, checkpoint serialization and page-local
editing. Three M1 tests cover glue-based line breaking, paragraph indentation and
empty paragraphs.