# Engine status The project is split into two repositories: `texrra-engine` (this Rust engine and HTTP server) and `texrra-web` (the static editor frontend). The engine discovers the frontend through `TEXRRA_WEB_DIR`, `../web`, or `./web`. Rust-native, Typst-inspired incremental LaTeX engine. No external XeLaTeX is invoked. The live server keeps compiled documents cached and only rebuilds when the source changes; the SVG preview is refreshed per page. ## Implemented - Headings: numbered `\section`/`\subsection`/`\subsubsection` and starred `\section*` variants (starred headings do not advance the counter). - Box material: `\rule` (raise/width/height), inline framed `\fbox`, block `\parbox`/`\minipage`, `\vbox`/`\vtop` (vertical material capture), inline `\mbox`, `\makebox[width][align]`, `\raisebox`, `center`, `\hrule` with `width`/`height`. - Fonts: Liberation Serif/Sans/Mono faces, bold/italic/monospace/sans declarations with group scoping, grouped text-style commands, true small caps (lowercase uppercase glyphs at 80% size), and sans/serif/mono small caps. - Paragraphs: Knuth-Plass breaking, TeX hyphenation patterns, justification, `\centering`/`\raggedright`/`\raggedleft` declarations and environments, first-line `\parindent` (17pt default, group-scoped, `\setlength`/ `\addtolength`/`\noindent` aware), and `\hfill`/`\hfil` infinite glue. - Pages: A4/A5/B5/Letter/Legal/Executive, landscape, geometry margins and text block, geometry-aware `\textwidth`/`\textheight`/`\linewidth`/ `\columnwidth` (as live named length registers), automatic pagination, `\newpage`/`\pagebreak`. Figures honor `[htbp]` hints: `[t]` is queued and placed at the top of the next page while following text fills the current page, `[b]` sits at the page bottom, `[p]` takes a float page, and `[h]` stays in the text flow. Tables queue `[t]` captions and rows at the top of the next page, sit at the page bottom for `[b]`, take a float page for `[p]`, and stay in the text flow for `[h]`. Page styles: default `plain` page numbers, `\pagestyle{empty|plain|fancy}`, `\thispagestyle`, fancyhdr `\fancyhead`/`\fancyfoot` (L/C/R) and `\lhead`/`\chead`/`\rhead`/`\lfoot`/`\cfoot`/`\rfoot`, with `\thepage` resolved at paint time; decoration tokens are expanded at the start of the document, after packages have renewed macros, and fancy headers get a 0.4pt rule. - Notes: `\footnote{...}` page-bottom insertion area with separator rule, superscript markers, and title/author `\thanks`. - Contents: `\tableofcontents`, `\listoffigures`, and `\listoftables` generate headings plus entries from numbered chapters/sections and captioned figures/tables, with dotted leaders and page numbers resolved after pagination. - Chapters: `\chapter` is a level-0 heading; chapter numbers prefix section numbers (`1.1`, `1.1.1`) and reset lower counters. Chapters after the first block start on a new page. - Abstract: the `abstract` environment is a 20mm inset quotation with a bold heading, matching the class styles used by the arXiv template. - Class sizes: 10pt/11pt/12pt set the body size (article defaults to 10pt) and propagate through headings, title material, lists, tables, block boxes, footnotes, and the default paragraph indent (10/12pt use 15pt; 11pt uses 17pt). - Title blocks: a document-level `\renewcommand{\maketitle}` replaces the engine title layout and can use `\@title`/`\@author`/`\@date`. Loading `arxiv.sty` selects a native preprint title style (rules, small-caps title, `\undertitle`, two-column author/affiliation blocks, long date, empty first page style), so arXiv PDFs no longer fall back to the plain article title. Loading `sn-jnl` selects a structured journal title style built from `\author`/`\affil`/`\abstract`/`\keywords` metadata: centered title, numbered authors and affiliations, e-mail line, abstract, and keywords. Class/package replacements of `\maketitle` itself remain ignored. - Line spacing: ordinary text lines use a TeX baseline grid (1.2em height, 0.8em ascent); boxes/rules keep their measured vertical metrics. - Classes/packages: built-in classes, local `.cls`/`.sty`, paper options, `\DeclareOption`/`\ProcessOptions`/`\ExecuteOptions`/option passing. - Compatibility: spacing macros (quad/qquad/thin/en/med/thick, `\vspace*`, `\hspace*`, skips), text symbols/letters/punctuation, break advisories, metadata, `\paragraph` run-in headings, citations/references, tables/lists/images. - Tables: natural column widths, centered tables, `\multicolumn` spans with per-span alignment, and partial `\cmidrule`/`\cline` rules over a column range. The arXiv table's full-width rule measures ~61.6mm, matching the XeLaTeX reference's ~61.2mm; math-containing cells are measured from a character estimate because inline math is painted as vector paths. - Citations: numeric citations by default; `natbib`/`arxiv.sty` selects author-year `\citet`/`\citep` from `.bib` metadata, formats bibliography entries in plainnat order (`First Last`, `In ...`, `pages`, publisher/year), adds deterministic `2014a`/`2014b` suffixes for duplicate author-year entries, indents continuation lines (plainnat hanging style), and drops numeric bibliography labels. - Pagination: the positioned renderer reserves a 3 mm descent guard at the page bottom (TeX `\maxdepth`) so the last baseline and its descender stay inside the page frame. - Preprint title blocks reserve the title/author `\thanks` footnote height on page one plus one spare baseline; the title-note reserve is settled after the paragraph so the body can use the full body goal, with a 1 mm guard keeping the closing line above the separator. Uses the arxiv class's 11 pt leading and reference title gaps (measured title/author/date/Introduction baselines match XeLaTeX within 0.3 pt); table cells get a 1 mm render-area tolerance so bottom floats at the page goal do not trip the frame check. - Live preview: paragraph cache, page-hash diffing, warm rebuilds in the low milliseconds for small edits. ## Remaining structural work See `docs/ROADMAP.md` for concrete implementation plans. ## Known approximations / gaps - Boxes: `\parbox`/`\minipage` are block-level; `\vbox`/`\vtop` capture and splice vertical material but do not expose an independent natural width or box baseline. - Pages: the figure/table queues only look one page ahead; table float-page queues are not implemented and there is no `\textfraction`/`\topfraction` tuning. Pagination is performed by the positioned renderer; the separate page-break planner was removed. - Notes: footnotes inside figure/table captions are collected and painted on the caption's page; footnotes inside floats or arbitrary boxes are not collected yet. The insertion area follows the page where the paragraph ends rather than the exact reference line. Heading keep-with-next is approximate, so a section heading can be left at the bottom of a page with its body on the next page. - Contents: chapter headings are listed with chapter-prefixed section numbers, but contents are not split per chapter. - Preprint title blocks: ORCID links in `\author` embed the bundled official ORCID logo (`assets/orcid-logo.png`, rasterized from the template's `orcid.pdf`) as a 2.2 mm image before the author name; the SVG preview keeps a rounded `rect` fallback. Hyperlinks use hyperref's green text colour; visible `\url` text, `\href` display labels, and ORCID author badges emit PDF `/Link` URI annotations (`/Annots`). Metadata baselines match the reference within 0.3 pt and page 1 keeps the same closing section-2 line as the reference. `printpdf 0.3.4` has no annotation API, so the link is added by reopening the finished PDF with lopdf and extending each page dictionary. ## Verification - `examples/hello.tex`, `examples/boxes.tex`, `examples/compat.tex` compile to one A4 page each; the arXiv template project compiles to 3 Letter pages. - All text faces are embedded Liberation Serif/Mono/Sans (arXiv PDF is about 0.29 MB and `pdffonts` reports only embedded CID TrueType faces); this avoids viewer-dependent glyph substitution. Tables use natural column widths and centered rules; preview and PDF share the same table line coordinates. - `cargo fmt --check` passes; `cargo test --offline` (79 tests: 71 compiler integration tests + 4 server tests + 4 unit tests) covers the three examples, the arXiv fixture, figure/table floats (top and bottom), newpage, page styles and `\thispagestyle`, SVG/PDF output, project API, static frontend assets, path traversal, the legacy `/texrra` endpoint, and page-hash cache stability. - Warm preview: hello ~0.6ms, arXiv ~13ms (release server, page layout cached). ## Verification snapshot - Compiler integration tests: 71; server tests: 4; unit tests: 4; total 79. - `cargo fmt --check` passes. - arXiv fixture: 3 Letter pages, ~0.29 MB; four serif faces and one monospace face embedded (bold/italic monospace falls back to the regular face). The bundled SubsetTTF faces are pyftsubset outputs with retained glyph ids and a filtered legacy kern table; a third 110-glyph ASCII/typographic tier is selected when the document charset fits. - Title/author/date/Introduction baselines within 0.3 pt of the XeLaTeX reference; page 1 keeps the closing section-2 line above the footnote. - Table 61.1 mm wide (reference 61.2 mm) with `\multicolumn` spans and partial `\cmidrule` rules; table rules in the SVG preview use absolute page coordinates, matching the PDF. - PDF link annotations are added by reopening the finished PDF with lopdf, since printpdf 0.3.4 has no annotation API. - Fonts: bundled reserved-glyph subsets in `assets/fonts-subset/` are used when the document charset is covered; arXiv PDF is about 0.29 MB. - New-template compatibility: the SIVP class file loads fully and `sn-article.tex` previews and exports a 17-page PDF (PDF figures render as placeholders). Its journal title block captures title, author/affiliation, corresponding-author stars, both e-mails, abstract, and keywords; class declaration option leakage is consumed. The Huawei E fragment compiles to 16 A4 pages. Generic support added for TeX `\if`/`\ifx`, `\newcount`, `\newdimen`, `\char`, `tabular*`/`tabularx`, math accents/operators/arrows, a 64-bit dimension scanner, and `geometry` `text={width,height}` blocks. Both fixtures are regression tests (`sivp_project_previews_and_exports_a_pdf`, `e_fixture_compiles`). - Lines whose justification ratio exceeds 3 fall back to natural spacing instead of stretching inter-word gaps across the measure. - Numeric bibliographies format author names as Surname, I. for standard journal styles.