31 KiB
Executable File
TeX-compatible incremental core (route D)
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.
Why route D
The v1 engine parses LaTeX into DocumentModel and lays it out with
hand-written algorithms. That gives true incremental preview, but it cannot be
page-identical for arbitrary .cls/.sty files: class files are TeX programs,
and their layout primitives (\vbox, \halign, \output, \twocolumn,
insertions, math lists, font metrics) are not executed.
Route D is a TeX-compatible execution/layout core designed for incremental operation from the start. It does not embed pdfTeX, XeTeX or Tectonic.
Layout::changed_pages/Engine::changed_pages()list the page indices whose sealed hash changed during the last edit.
M0 scope (this spike)
crates/texrra-tex-core currently provides:
VerticalItem::{Box, Glue, Penalty}andVerticalBoxas the first vertical list model;Unit::paragraphbacked by the M1 box/glue/penalty paragraph builder;Engine::layoutthat builds pages with a simple page goal;Checkpointbefore every top-level unit, containing the completed-page count, used vertical space and current page items;Pagehashes derived from both vertical items and the contributing unit sources;Engine::editwhich restores the checkpoint before the edited unit, re-executes only the suffix, compares page hashes, and reportsrecomputed_pages;Unit::paragraph_stylerecords whether a unit is text and can be re-flowed byEngine::edit; structural units (halign, insertion, float) are never rewritten from a plain source string.- serde round-trip for checkpoints.
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}andHorizontalBoxas the horizontal list model;ParagraphStylewithline_width,par_indent,line_heightand glue stretch/shrink;Cmr10Metrics, a CMR10 ASCII width table extracted fromcmr10.tfmwithtftopl, plus the fontdimen space/stretch/shrink values;- an item-stream dynamic program over character boxes, glue and penalty
breakpoints that minimizes TeX demerits (line penalty, badness, break
penalties and adjacent fitness changes), applies
par_indentto the first line, and bakes the justification into the glue widths of every non-final line; Paragraph { lines, height, width }and a paragraph-backedUnit.
M1 reads real CMR10 TFM metrics at runtime (advances, height/depth, italic
correction, kern pairs, ff/fi/fl/ffi/ffl ligatures and the fontdimen glue
parameters), hyphenates with TeX Live's hyph-en-us patterns and exceptions
(\lefthyphenmin=2, \righthyphenmin=3), and reproduces TeX's paragraph
breaker: pass 0 uses \pretolerance without hyphenation, pass 1 uses
\tolerance, and a third pass with \tolerance=10000 runs only when
\emergencystretch is positive. With zero emergencystretch TeX's final pass
keeps \tolerance and forces overfull breaks through artificial demerits;
the fallback here mirrors that choice by taking the longest prefix within
tolerance and otherwise the first prefix that overflows. Justification
stretches normal glue past its nominal stretch (badness simply exceeds 100)
and clamps shrink at the declared limit, so overfull lines stay overfull
exactly as in TeX. Each line can take its measure and left offset from
\hangindent/\hangafter or an explicit \parshape list; the display list
honours the same offsets. The bounds and hyphen demerits are ParagraphStyle
fields mirroring \pretolerance, \tolerance, \hyphenpenalty and
\exhyphenpenalty, \linepenalty, \adjdemerits,
\doublehyphendemerits, \finalhyphendemerits and \emergencystretch,
plus document-level \hyphenation exceptions; \hyphenpenalty at 10000 or
more disables hyphenation and switches the fallback to a first-fit scan.
tests/oracle.rs compares a matrix of measures (90, 100, 110, 120, 130, 150, 160, 180, 200, 220 and
240pt) against pdfLaTeX: every fixture matches word for word and within 0.05pt
horizontally. The narrowest measures exercise hyphenated and overfull breaks (including a
final line held at its declared shrink limit), 130-160pt the final-pass
overfull box, and 180-240pt ordinary tolerance solutions. Two further fixtures pin register behaviour at 120pt:
\pretolerance=10000 stops before hyphenation and \hyphenpenalty=10000
inhibits it, leaving the overfull first-fit lines TeX produces. A 120pt
fixture with \hangindent=20pt \hangafter=1 checks every line origin
against pdfLaTeX as well as the word positions inside each line, and a
\parfillskip=0pt fixture checks that a final line without fil glue is
justified like any other line (the default 0pt plus 1fil leaves it short).
Two 150pt fixtures pin explicit interword glue: \spaceskip replaces the
font glue (width kept, stretch/shrink following the space factor) and
\xspaceskip is used verbatim once the factor reaches 2000; neither adds
\fontdimen7. A 150pt fixture pins \emergencystretch=10pt (three lines instead of an
overfull pair) and another pins \leftskip=20pt (narrowed measure and
shifted origins). route_d_multiline_bands_track_pdftex rasterizes the same
paragraph in both engines and compares ink bands, covering baseline placement
and justification.
Target architecture
- Persistent TeX VM state: macros, registers, fonts, counters, output queue.
- Stable IDs for top-level units.
- Checkpoint at page boundaries plus unit boundaries.
- Dependency graph for labels, references, counters, TOC and citations.
- Dirty propagation: after a local edit, replay from the nearest checkpoint and stop at the first unchanged page hash.
- Float/footnote queues restored with the checkpoint.
Milestones
| 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) |
partial: item stream, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, \hangindent/\parshape, \parfillskip, sentence spacing, \spaceskip/\xspaceskip, \looseness, \baselineskip/\lineskip/\parskip interline glue, pdfLaTeX oracle matrix 90-240pt plus register, geometry, \sfcode and vertical-glue fixtures; generic fil glue and \prevgraf next |
| M2 | page builder + \output, \vsize, \topskip, footnotes, floats |
partial: \vsize page goal, \topskip, forced penalties, Insertion reserve, running Marks, OutputRoutine hook, top/bottom Float placement; page::PageBuilder scores candidate breakpoints with TeX page badness, glue setting, \topskip/\maxdepth, and Engine::layout_paged uses it for documents whose units are single vertical items, while the scrolling builder remains the default; \output is interpreted for a \shipout/\ifdim/\ifnum/\ifodd/\ifcase subset; \pageno, \outputpenalty and \deadcycles are readable registers and PageFragment::penalty carries the break penalty |
| M3 | \halign, \omit, \span, \multispan, booktabs/longtable |
partial: source parsing, natural column widths, spans, rule rows, 10pt display-list painting and row-level page splitting; no booktabs/longtable parity yet |
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | partial: token parser, atom boxes with CMR10 metrics, delimiter scaling, accents and a display-list painter; no CMEX size variants or TeX math spacing classes yet |
| M5 | NFSS/TFM metrics, CM/Latin Modern | same line/page breaks as reference |
| M6 | class/package execution (article, sn-jnl) |
Overleaf page-count parity |
| M7 | \special, PDF XObjects, hyperref annotations |
PDF structure parity |
Current limits
- The M1 paragraph builder parses CMR10 TFM metrics (widths, height/depth,
italic correction, kern pairs, ligatures), applies TeX Live's en-US
hyphenation patterns and runs TeX's tolerance passes with demerits. The
tolerance bounds, break penalties and flagged demerits are modelled,
\hyphenationexceptions are inserted into the pattern trie, and\hangindent/\hangafter/\parshapechange each line's measure and left offset, and\parfillskip(with or withoutfil) decides whether the last line is justified. Sentence spacing follows TeX's default\sfcodevalues: interword glue stretch is multiplied by the space factor, shrink is divided by it,\fontdimen7is added from factor 2000, and\frenchspacingdisables the effect.ParagraphStyle::space_factor_codescarries explicit\sfcodeassignments, which replace the built-in table for that character; a zero code leaves the running factor unchanged, as in TeX. Explicit\spaceskip/\xspaceskipreplace the font glue, and hyphenation applies to a word's letter core so trailing punctuation does not suppress the pattern lookup (pdfTeX breaksepsilon:asep-).\loosenessshifts the paragraph by whole lines when the requested count lies between one and nine lines away from the natural count (the adjustment is reverted when no feasible layout exists). Interline glue follows TeX: each baseline advances by\baselineskipwhen the resulting gap clears\lineskiplimit, otherwise by\lineskip;\parskipis appended between paragraph units in the vertical list. When a paragraph does not fit on the page, the scrolling builder splits it at line boundaries (Paragraph::split_at): the fragment keeps its baseline grid on the next page,\parskipis not charged inside the paragraph, and only a single unsplittable line is allowed to overflow at the top of a page. Remaining gaps are genericfil/fillglue orders outside\parfillskipand\prevgraf.
The pdfLaTeX oracle pins the 90-240pt measure matrix plus \hangindent,
\parfillskip, sentence-spacing and \looseness fixtures; all match and no
oracle fixture is ignored.
\middle|inside\left...\rightis accepted as a delimiter symbol (not yet stretched).\sqrt[n]{x}carries an optional degree atom;\left.is an empty delimiter with zero width.MathAtom::Accent { accent, base }parses\hat,\widehat,\tilde,\widetilde,\bar,\overlineand\vec; it adds accent height without changing the base width.MathAtom::Smash { body, top, bottom }implements\smashand\smash[t]/\smash[b].MathAtom::Phantom { body, horizontal, vertical }implements\phantom,\hphantom,\vphantomdimension-only boxes.MathAtom::BigOperator { name }gives\sum/\prod12pt width and\int8pt width with larger height/depth than text.MathAtom::Limits { base, sub, sup }gives\sum,\prod,\int,\lim,\sup,\infabove/below scripts.MathAtom::Classed { class, body }implements\mathord,\mathop,\mathbin,\mathrel,\mathopen,\mathclose,\mathpunctand\mathinnerspacing overrides.MathAtom::SizedDelimiter { delimiter, size }parses\big/\Big/\bigg/\Bigg(andl/rvariants); extents are 8/11/14/17pt.MathAtom::Stack { top, base, above }parses\overset/\underset; the decoration contributes 1pt of extra separation.MathAtom::Brace { base, above }parses\overbrace/\underbraceand adds 2pt of height or depth.MathAtom::Binomial { numerator, denominator }parses\binom{n}{k}/\dbinom/\tbinom; layout stacks the arguments with a 4pt delimiter allowance.\mathcal,\mathbb,\mathbf,\mathit,\mathsf,\mathtt,\mathfrak,\mathnormalparse their argument as uprightTextfor metrics; visual alphabet selection waits for the NFSS math font layer.- Named operators (
\max,\min,\sin,\log,\det, ...) parse as uprightTextatoms. MathAtom::Underline { base }parses\underline{...}and adds 2pt depth without changing width or height.MathAtom::Text(String)parses\text{...}and\mathrm{...}; widths use upright CMR glyphs and spaces use the font space width.MathAtom::Delimited { left, right, body }- Delimiter width grows with the body extent: each non-
.delimiter is0.35 * max(body height + depth, 7pt)wide. and\left...\rightparsing grow the delimiter box with the body height/depth. MathClassand TeX's 0/3/4/5mu inter-atom table add spacing for binary/relation/open/close/punctuation atoms inMathAtom::Row.parse_mathconverts a small TeX math subset (symbols,{}groups,_/^scripts,\frac,\sqrt) intoMathAtom::Row.MathAtom::{Symbol, Script, Fraction}andlayout_mathproduceMathBox { width, height, depth };Unit::mathturns an atom into a vertical box. Parsing TeX math tokens and painting remain future M4 work.- M1 now inserts TeX en-US hyphenation points as
HorizontalItem:: Discretionary: a break adds the hyphen width, a non-break keeps zero width. The line breaker scores these breakpoints with the same glue model as spaces. Unit::halignlays out natural column widths, multi-column spans and rule rows as aVerticalItem::Halign;Halign::cell_boxreturns each cell's aligned rectangle for a future painter. It is not yet painted by v2.- Pages that start with a float also honour
Document::top_skip. Unit::verticalandUnit::insertionbuild arbitrary vertical material and reserved-height page insertions; insertion height is deducted from the usable page goal and the material is attached toPage::insertions.Document::insertion_classessets a per-class page fraction; an insertion that would exceed the class limit ships the page and continues on the next one, splitting at item boundaries when the insertion itself is too tall. When only part of an insertion fits on the page where its anchor text ends, that part stays there and the remainder is held over to the next page, so later body text follows the held-over tail.Document::insertion_skipmodels TeX's\skip\footinsand is reserved once before the first insertion class on a page; it defaults to zero, andInsertionClass::skipoverrides it for a single insertion class.InsertionClass::multipliermodels\count<number>in thousandths: the page space a class reserves isheight * multiplier / 1000, so 2000 makes a 30pt insertion cost 60pt of page height.max_heightis the\dimen<number>absolute cap. Full layout, incremental replay and the item-boundary splitter all use the same reserved height. Overflowing insertions are split at item boundaries: the fitting head stays on the anchor page and the tail is held over to the following page.- Page breaking handles vertical boxes/glue,
Document::top_skipand forced vertical penalties (penalty <= -10000); positive penalties are recorded but not yet part of page badness.VerticalItem::Insertionmaterial is attached toPage::insertionsand reserves height from the page goal.VerticalItem::Markmaterial is collected intoPage::marksand included in the page hash.OutputRoutine::shipoutruns before sealing and may mutate each page; this models the\outputstage in Rust. The interpreted subset lives inoutput::OutputProgram(Document::output_routine), which understands\shipout\box255,\relax,\message{...}and\ifdim/\else/\fiover the page registers\pagegoal,\pagetotal,\vsize,\topskipand\maxdepth; it cannot yet change page goals. TopFloatmaterial is deferred to the next page when it arrives late; bottom floats reserve height on the current page and must satisfyDocument.text_fraction_percent(default 50%); a page holding only floats is sealed once it leaves less than that fraction for text. - 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_typesetand are unchanged.
Verification
cargo test -p texrra-tex-core --offline
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.
Unit::halign_from_source parses & rows, \\ separators, \omit,
\span, \multispan{n} and \hline rule rows.
Unit::halign_from_source_with_template additionally accepts an l/c/r
column template.
VerticalItem::Rule { width, height } and Unit::rule(id, width, height)
add filled rules to the vertical list; rules consume page height like boxes.
\not becomes MathAtom::Negated, preserving the base atom's geometry
for a later overlaid slash.
\noalign{...} material in a halign source is skipped while rows are scanned.
\bmod/\pmod{n} parse to upright mod rows, with \pmod wrapping its argument in (mod ...).
\pmod{n} is a Classed relation, and \not inherits the base atom's math class for spacing.
\mathinner{...} uses MathClass::Inner with 3mu on either side.
\boxed{x} adds 3pt padding around its body in the math model.
Unit::vskip(id, height) adds a vertical glue item to the page list.
Unit::penalty(id, value) adds a vertical penalty; values <= -10000 force a page break.
\stackrel{top}{base} shares the Stack layout with \overset.
\overrightarrow/\overleftarrow parse as arrow accents (U+20D7/U+20D6).
\widecheck and \dddot map to U+030C and U+20DB accents.
Milestone status (route D)
| Milestone | State | Notes |
|---|---|---|
| M0 checkpoint engine | done | page list, page hashes, snapshot/restore, edit replay |
| M1 horizontal/paragraphs | partial | boxes/glue/penalties, CMR10 metrics, TeX Live en-US hyphenation, TeX demerits and tolerance passes, \hangindent/\parshape, \parfillskip, sentence spacing with default and custom \sfcode/\frenchspacing, explicit \spaceskip/\xspaceskip, \baselineskip/\lineskip/\parskip interline glue, pdfTeX oracle matrix 90-240pt plus register, geometry and vertical-glue fixtures |
| M2 vertical/page builder | partial | vsize, topskip, insertions, marks, Rust output hook, top/bottom floats, float-page/text fractions, rules, vskip, penalties; page::PageBuilder scores breakpoints with page badness and penalties and models \topskip/\maxdepth; Engine::layout_paged builds pages through it for documents made of box/glue/penalty/mark vertical material (a unit may span pages), while floats and incremental replay still use the scrolling path, insertions are placed through the builder too; \output interpreted for a \shipout/\ifdim/\ifnum register subset over page globals and \outputpenalty/\pageno/\deadcycles |
| M3 halign | partial | natural columns, spans, omit, hline rows, templates, noalign skip, rules; no PDF painter |
| M4 math | partial | atoms, scripts, fractions, roots, delimiters, accents, operators, classes, braces, boxed, negated; no math painter/shrink wrapping |
| M5 NFSS/TFM | partial | runtime cmr10.tfm widths/heights/depths/kern pairs and ff/fi/fl/ffi/ffl ligatures; text faces embed Liberation Serif/Mono as Type0 CID fonts with Identity-H, ToUnicode and width arrays; used faces embed per-document TrueType glyf subsets that keep the original glyph IDs, include composite components, and carry a matching ToUnicode CMap; ASCII documents use the compact tier; no Base-14 dependency; SVG carries family/weight/style |
| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; class/package execution absent |
| M7 incremental integration | partial | route-D preview/PDF/edit endpoints plus opt-in ?engine=route-d project preview, content-based page hashes and section/emphasis/display-math/itemize/enumerate/description/quote/center/flushright mapping; editor toggle in texrra-web; inline math pending |
v1 remains the production renderer; the route-D core is additive and tested independently.
\substack{a\\b} parses each row and stacks them as MathAtom::StackLines.
\mathring{x} is the U+030A ring accent.
\overleftrightarrow uses U+20E1.
Unit::mark(id, class, text) and Unit::float(id, placement, width, height) are convenience constructors for M2 page items.
\mathop uses the Op spacing class (3mu against ordinary atoms).
\mathstrut is a zero-width strut with 7pt height and 2pt depth.
M3 painter: Page::display_list() and Halign::display_list() produce absolute text, rule and line primitives. DisplayList::to_svg() writes a standalone SVG; paragraph glyphs and math atoms are painted at their measured positions.
PDF writer: crates/texrra-tex-core/src/pdf.rs writes multi-page PDF 1.4 with five embedded Liberation Type0/CID faces (Identity-H + ToUnicode + /W arrays), filled rectangles, diagonal rules, raw-RGB /XObject images, /Annots URI links and arbitrary /special operators. Ligature substitution and line-end italic correction are implemented; full NFSS family switching remains open.
M5 (partial): display-list text carries FontFace::{Roman,Bold,Italic,BoldItalic,Mono}. Roman/Bold/Italic/BoldItalic/Mono text are painted with embedded Liberation Type0/CID fonts, each with a ToUnicode CMap and /W width array. cmr10.tfm is parsed at runtime for widths, heights/depths, kern pairs and ff/fi/fl/ffi/ffl ligatures; line-end and math-script italic corrections and monospace/sans paragraph faces are applied; true NFSS family switching remains open. Unit::paragraph now builds its item stream with layout_paragraph_with_font, so CMR10 advances, kerns and ligatures drive paragraph widths; each glyph box also carries the TFM height/depth, and the painter emits 10pt glyphs and the Type0 /W array reports CMR10 advances, and ligature boxes paint their component letters, so pdftotext keeps word boundaries instead of inserting spaces between letters.
M6 (partial): DisplayItem::Image becomes a PDF XObject; DisplayItem::Link becomes /Annots /Subtype /Link /URI; DisplayItem::Special injects raw content-stream operators. SVG previews show images as grey rectangles and specials as comments.
M2 (partial): Page::display_list_with_goal(page_goal) places insertion material at page_goal - insertion_height, adds a 0.4pt separator above footnotes, splits oversized insertions at item boundaries, and paints top/bottom floats from their vertical content at the page edges; empty floats keep a dimension rectangle. Floats also size themselves from content, respect text_fraction_percent, respect top_fraction_percent (TeX \topfraction, default 70%) and bottom_fraction_percent (TeX \bottomfraction, default 30%), and can take a dedicated float page. The incremental edit path applies the same float fractions, float number limits, insertion-class limits and per-class skip rules as full layout. Document::float_sep (TeX \floatsep, default 12pt) reserves a gap between stacked floats of the same placement in both paths. Document::text_float_sep (TeX \textfloatsep, default 20pt) reserves exactly one gap between the float block and the body text on a page that has both, again in both paths; Page::display_list_with_layout(page_goal, text_float_sep) applies the same gap when rendering, while display_list_with_goal stays gap-free for callers that do not know the document settings. Float material at the top of a page starts at the top margin: \topskip is consumed only by body text, matching TeX float pages. FloatPlacement::Here models [h] floats: they keep their place in the body flow with Document::in_text_sep (TeX \intextsep, default 12pt) above and below, move to the next page when they do not fit, and count against \totalnumber. The page stores the float's gap_after so the display list advances the flow by the same amount the builder reserved. A standalone page::PageBuilder implements TeX's candidate-breakpoint cost model (page badness from accumulated glue stretch/shrink plus break penalties, \topskip for the first box, \maxdepth depth shifting) with eight unit tests, and every fragment records the penalty that broke it. Engine::layout_paged now builds pages through it for documents whose units are single vertical items (boxes, rules, paragraphs, math, haligns, glue, penalties, marks and insertion classes, including per-class limits and held-over material); Document::max_depth feeds TeX's \maxdepth into the builder, and among equal-cost breakpoints the candidate closest to the page goal wins, so an overfull page takes the least overfull break. Paragraphs also split across pages at line boundaries, so body material no longer overflows a page as one box. Document::h_offset and v_offset (TeX \hoffset/\voffset, default zero) feed pdf::PageOrigin, and display_lists_to_pdf_with_origin translates the page body without moving the sheet; a route-D fixture checks a 10pt/20pt shift against pdftotext -bbox, and the route-D PDF endpoint strips leading \hoffset/\voffset dimension assignments from the source and applies them. Engine::top_mark, first_mark and bot_mark implement TeX's carried mark registers per class. Document::output_routine runs an interpreted \output program over the paged fragments (output::OutputProgram: \shipout\box255, \relax, \message, \ifdim, \ifnum, \ifodd and \ifcase over the page registers, now including \pageno, \outputpenalty and \deadcycles), dropping pages the routine does not ship. Floats and the incremental checkpoint replay still use the scrolling builder, which remains the default until those pieces have a paged equivalent.
M3 (partial): Unit::halign normalizes column widths, intercolumn gaps, row heights and cell text widths to scaled points; the painter uses 10pt glyphs in 12pt rows. Rules and spans are painted; tall tables split at row boundaries (Halign::split_for_height) with column widths preserved.
Math coverage includes fractions/roots, scripts, \left...\right with body-scaled delimiters, \middle, \big/\Big/\bigg/\Bigg and their l/r forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), \text/\mathrm, \overbrace/\underbrace, \overset/\underset, \binom, \cancel/\bcancel/\xcancel, \bmod/\pmod, fence symbols, \operatorname* and \mathop limits.
Paragraph units carry a ParagraphFont; Unit::paragraph_with_face and Unit::paragraph_with_style_and_face select Roman, bold, italic, mono, or sans. The corresponding Computer Modern TFM (cmr10, cmbx10, cmti10, cmbxti10, cmtt10, cmss10) supplies advances, kerns, ligatures, and italic correction for layout, while the display list and PDF select the matching Liberation face. Engine::edit preserves the face when reflowing an edited paragraph.
The crate currently has 235 unit tests plus seven route-D integration tests and thirteen oracle fixtures. Workspace verification: cargo fmt --all -- --check; cargo test --workspace --offline runs 353 tests (235 route-D unit, 7 route-D integration, 13 oracle, 71 v1 integration, 20 server, 4 v1 unit, 1 core unit, 2 binary units), with none ignored. v1 remains the live server path.
M0 incremental demo
crates/texrra-tex-core/examples/incremental_article.rs builds a three-paragraph article, edits the middle paragraph, and prints the pages that checkpoint replay rebuilt. The expected result is page 2 only when the edit does not change page 1's content or the page count.
Run it with:
cargo run -p texrra-tex-core --example incremental_article
PDF smoke example
crates/texrra-tex-core/examples/pdf_display.rs writes a Letter-size PDF with text, a rule, a 2x2 RGB XObject and a URI link:
cargo run -p texrra-tex-core --example pdf_display > /tmp/route-d.pdf
Open milestones
The staged program that closes these milestones is described in
ROUTE_D_PLAN.md.
Route D currently covers M0-M4/M6 as a working subset. The remaining milestones are deliberately open rather than approximated:
- M1: generic
fil/fillglue orders and\prevgrafare still open; the tolerance, penalty and demerit registers,\hyphenationexceptions,\hangindent/\parshape,\parfillskipwith or withoutfil,\looseness,\baselineskip/\lineskip/\parskipinterline glue, the default\sfcode/\frenchspacingsentence spacing, and explicit\spaceskip/\xspaceskipare modelled. - M2: the scrolling builder still drives
Document;page::PageBuilderimplements TeX's candidate-breakpoint cost (badness + penalty, glue stretch/shrink,\topskip,\maxdepth) andEngine::layout_pagedruns it for simple documents, but floats and incremental replay need a paged equivalent before it can become the default; paper margins remain open, and the\outputinterpreter only covers the shipout/ifdim/ifnum/ifodd/ifcase subset (explicit\hoffset/\voffsetoffsets are applied by the PDF writer). - M5:
cmr10.tfmis parsed at runtime with widths, glyph heights/depths and kern pairs. only used text faces embed Liberation Serif/Mono as Type0/Identity-H; each face is subset to the glyphs actually used (composite components included, glyph IDs retained); FontFile2 and ToUnicode streams use Flate compression; the ToUnicode CMap follows the used characters; ff/fi/fl/ffi/ffl ligatures come from TFM, and CMR10 italic corrections are applied at line ends; full NFSS family switching is not implemented. - M6:
\output,\insert, mark/float output policies, class-file execution and math limit policies are only partially modeled;OutputRoutine::wants_breakcan force a page break between units, and insertion material is stacked by class from the page bottom;Document::output_routineis interpreted per page byoutput::OutputProgramfor the shipout/ifdim/ifnum/ifodd/ifcase subset (with\pageno,\outputpenalty,\deadcycles), whileOutputRoutineremains the Rust hook. - Page hashes cover rendered items/insertions/marks/floats, not source-dependency metadata, so replaying an earlier page cannot change its hash merely by re-attaching source hashes.
- M7:
POST /api/route-d/preview,/api/route-d/pdfand/api/route-d/edit/{unit}expose route-D pages, PDF export and edit diff. The project preview can opt in withPOST /api/projects/{id}/preview?engine=route-d;route_d::project_preview_jsonstrips the preamble/body wrapper and keeps a project-scoped(paragraphs, Engine)session. An unchanged source returnschangedPages: []andrecomputedPages: 0; same-count paragraph edits and structural edits that keep a non-empty paragraph prefix are rebuilt from the first difference throughEngine::relayout_from, which reuses the sealed pages before that checkpoint; edits without a reusable prefix fall back to a full layout. The v1 semantic pipeline remains the default fallback. LaTeX-to-route-D semantic mapping is still a subset, androute_d_page_matches_pdftex_raster_geometrylays out a 480pt CMR10 paragraph at the same scaled-point geometry the server uses, rasterizes the route-D PDF and a pdfTeX Letter page at 72 dpi, and asserts matching ink line count plus left/right/bottom edges. It skips on hosts withoutpdflatex/pdftoppm. Exact glyph-outline pixel equality is still open because the two paths use different font outlines. \middledoes not scale with its enclosing delimiter; math delimiters are scaled glyphs rather than TeX delimiter variants.