Default to route-D with TEXRRA_ENGINE

This commit is contained in:
gloamxun committed 2026-10-24 23:03:34 +08:00
1 parent b30bafca2b
commit 91a75820a4
5 files changed
+64 -10

No files matched your search

+1 -1
View File
@@ -604,6 +604,6 @@ assignments from the submitted source. Page marks collected by `\mark` are expos
`Engine::top_mark`, `first_mark` and `bot_mark` with TeX's carry-forward rules.
`Document::insertion_classes` caps each insertion class to a page fraction and defers overflow to the next page (the paged builder applies the same limits and carries overflow onto dedicated pages), and `InsertionClass::multiplier` applies TeX's `\count<number>` reserve factor; `Document::insertion_skip` models `\skip\footins` once per page before the first insertion class, and `InsertionClass::skip` overrides it for one class. `Engine::layout_paged` feeds the same material through `page::PageBuilder`, which places top floats at the head of a page, defers a late float, reserves `Document::text_float_sep` above the body and applies the insertion class limits; bottom floats sit at the page bottom with `Document::float_sep` between them and a `Document::bottom_fraction_percent` cap, while in-text floats flow inline with their `Document::in_text_sep` gaps counted as body height. Vertical glue is set after the break: `Document::ragged_bottom` defaults to TeX's `\raggedbottom`, and setting it false applies `\flushbottom`, stretching `StretchGlue` so the page body reaches the goal; glue of the highest order with stretch absorbs the whole setting, so `\vfil` makes short pages free. The v1 `/preview` and project APIs are unchanged and remain the default.
Project previews can opt into the new core with `POST /api/projects/{id}/preview?engine=route-d`; the same project preview without the query keeps the v1 pipeline. The web client exposes this as the `引擎: v1` / `引擎: Route-D` toggle in the preview toolbar; the choice is stored in `localStorage` and switches both the preview request and `POST /api/projects/{id}/pdf`, since the PDF handler honors the same `engine=route-d` query. Route-D project previews keep a session, so an unchanged source reports zero recomputed pages; text edits and structural edits with an unchanged paragraph prefix rebuild from the first difference through `Engine::relayout_from`, reusing the sealed pages before it, while edits without a reusable prefix fall back to a full layout. `POST /api/route-d/edit/{unit}` applies one paragraph edit to the last route-D
Project previews can opt into the new core with `POST /api/projects/{id}/preview?engine=route-d`; the same project preview without the query keeps the v1 pipeline unless the server is started with `TEXRRA_ENGINE=route-d`, which makes route-D the default. An explicit `?engine=v1` always forces the old pipeline. The web client exposes this as the `引擎: v1` / `引擎: Route-D` toggle in the preview toolbar; the choice is stored in `localStorage` and switches both the preview request and `POST /api/projects/{id}/pdf`, since the PDF handler honors the same `engine=route-d` query. Route-D project previews keep a session, so an unchanged source reports zero recomputed pages; text edits and structural edits with an unchanged paragraph prefix rebuild from the first difference through `Engine::relayout_from`, reusing the sealed pages before it, while edits without a reusable prefix fall back to a full layout. `POST /api/route-d/edit/{unit}` applies one paragraph edit to the last route-D
document and returns the same page list plus `changedPages` and
`recomputedPages`, exposing the checkpoint/page-hash diff from the core.
+1 -1
View File
@@ -48,7 +48,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`,
`\bottomnumber`, `\totalnumber`), insertion classes (`\skip`, fraction and
absolute limits, splitting), marks, Rust output hook, multi-page PDF, and the
route-D service endpoints (`/api/route-d/preview|pdf|edit`, project preview and
PDF opt-in with `?engine=route-d`). 685 workspace tests are green and no oracle
PDF opt-in with `?engine=route-d`). 686 workspace tests are green and no oracle
fixture is ignored.
Status after G1 (P0-P2): the paragraph model reproduces TeX's passes,
+2 -2
View File
@@ -333,7 +333,7 @@ for a later overlaid slash.
| M4 math | partial | atoms, scripts, fractions (including infix `\over`/`\atop`/`\choose`), roots, delimiters, accents, operators, classes, braces, boxed, negated, math alphabets (incl. `\mathcal`, `\mathbb` and `\mathfrak`), `align`/`gather` rows with per-row tags; 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; route-D PDFs embed Knuth's Computer Modern Type1 programs (cmr10/cmbx10/cmti10/cmbxti10/cmtt10/cmss10/cmssbx10/cmssi10/cmcsc10/cmsl10/cmbxsl10/cmitt10) as `/Subtype /Type1` fonts with `/FontFile` (`Length1/2/3`), `/Encoding /Differences` and TFM `/Widths`, falling back per face to Liberation when the program does not encode every character |
| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; route-D reads `\documentclass` size options (10/11/12pt) into the paragraph base size and `\baselineskip`, executes `\newcommand`/`\renewcommand` macros textually (with numbered arguments and an eight-pass recursion guard), and expands `geometry`, `\setlength`, title/author/date, `\maketitle`, sectioning, theorem, float and bibliography markup; executing `.cls`/`.sty` files remains 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/inline-math/itemize/enumerate/description/quote/center/flushleft/flushright mapping; editor toggle in `texrra-web`; project route-D previews are memoised by a hash of the expanded source (32 entries) and invalidated automatically when the source changes; inline `$...$`/`\(...\)` math is laid out inside 10pt paragraphs, while larger paragraphs keep delimiters literal; `\href` labels paint PDF `/Link` URI annotations over their runs |
| 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/inline-math/itemize/enumerate/description/quote/center/flushleft/flushright mapping; editor toggle in `texrra-web`; project route-D previews are memoised by a hash of the expanded source (32 entries) and invalidated automatically when the source changes; a deployment can default to route-D with `TEXRRA_ENGINE=route-d`, and an explicit `?engine=v1` still overrides it; inline `$...$`/`\(...\)` math is laid out inside 10pt paragraphs, while larger paragraphs keep delimiters literal; `\href` labels paint PDF `/Link` URI annotations over their runs |
v1 remains the production renderer; the route-D core is additive and tested independently.
@@ -367,7 +367,7 @@ Math coverage includes fractions/roots, scripts, `\left...\right` with body-scal
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`, `cmssbx10`, `cmssi10`, `cmcsc10`) supplies advances, kerns, ligatures, and italic correction for layout, the display list selects the matching face, and the PDF writes Computer Modern Type1 outlines for each built-in face (`cmr10`/`cmbx10`/`cmti10`/`cmbxti10`/`cmtt10`/`cmss10`/`cmssbx10`/`cmssi10`/`cmcsc10`, plus `cmmi10` for mathematical italic letters, `cmsy10` for math symbols and `cmex10` for big operators), falling back to Liberation subsets only for characters the Type1 encodings cannot address. `Engine::edit` preserves the face when reflowing an edited paragraph.
The crate currently has 405 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 685 tests (405 route-D unit, 121 engine binary unit, 8 route-D integration, 35 oracle, 71 v1 integration, 40 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
The crate currently has 405 unit tests plus eight route-D integration tests and thirty-five oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 686 tests (405 route-D unit, 121 engine binary unit, 8 route-D integration, 35 oracle, 71 v1 integration, 41 server, 4 engine unit, 1 core unit), with none ignored. v1 remains the live server path.
### M0 incremental demo
+14 -2
View File
@@ -728,7 +728,7 @@ fn handle_project_request(
Ok(source) => source,
Err(error) => return respond_api_error(request, 422, &error),
};
if query_param(url, "engine").as_deref() == Some("route-d") {
if uses_route_d(url) {
let expanded = expand_project_source(&source, &store, id);
let key = route_d_cache_key(id, &expanded);
if let Some(json) = route_d_cached_preview(&key) {
@@ -792,7 +792,7 @@ fn handle_project_request(
Ok(source) => source,
Err(error) => return respond_api_error(request, 422, &error),
};
if query_param(url, "engine").as_deref() == Some("route-d") {
if uses_route_d(url) {
let expanded = expand_project_source(&source, &store, id);
return match route_d::pdf_bytes(&expanded) {
Ok(pdf) => respond_pdf(request, pdf),
@@ -845,6 +845,18 @@ fn project_json(info: &projects::ProjectInfo) -> String {
)
}
/// Chooses the renderer for a request. An explicit `engine` query parameter
/// wins, then the deployment-wide `TEXRRA_ENGINE` default, then v1.
fn uses_route_d(url: &str) -> bool {
match query_param(url, "engine").as_deref() {
Some("route-d") => true,
Some(_) => false,
None => std::env::var("TEXRRA_ENGINE")
.map(|engine| engine == "route-d")
.unwrap_or(false),
}
}
fn query_param(url: &str, name: &str) -> Option<String> {
let (_, query) = url.split_once('?')?;
for pair in query.split('&') {
+46 -4
View File
@@ -40,6 +40,10 @@ struct TestServer {
impl TestServer {
fn start(label: &str) -> Self {
Self::start_with_env(label, &[])
}
fn start_with_env(label: &str, extra_env: &[(&str, &str)]) -> Self {
let stamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("clock")
@@ -65,7 +69,8 @@ impl TestServer {
let port = free_port();
let log = File::create(root.join("server.log")).expect("create server log");
let child = Command::new(env!("CARGO_BIN_EXE_texrra"))
let mut command = Command::new(env!("CARGO_BIN_EXE_texrra"));
command
.arg("serve")
.arg(root.join("hello.tex"))
.arg(port.to_string())
@@ -73,9 +78,11 @@ impl TestServer {
.env("TEXRRA_WEB_DIR", &web)
.env("TEXRRA_PROJECTS_DIR", root.join("projects"))
.stdout(Stdio::null())
.stderr(Stdio::from(log))
.spawn()
.expect("spawn texrra serve");
.stderr(Stdio::from(log));
for (key, value) in extra_env {
command.env(key, value);
}
let child = command.spawn().expect("spawn texrra serve");
let mut server = Self { child, port, root };
server.wait_ready();
server
@@ -276,6 +283,41 @@ fn project_preview_expands_included_files() {
assert!(svg.contains(">B</text>"), "{svg}");
}
#[test]
fn project_preview_uses_the_engine_default() {
let server = TestServer::start_with_env("route-d-default", &[("TEXRRA_ENGINE", "route-d")]);
let main = "\\documentclass{article}\n\\begin{document}\nInline $x$ math.\n\\end{document}\n";
let put = server.request(
"PUT",
"/api/projects/hello/file?path=hello.tex",
main.as_bytes(),
"text/plain; charset=utf-8",
);
assert_eq!(put.status, 200, "{}", put.text());
let preview = server.request(
"POST",
"/api/projects/hello/preview",
&[],
"application/json",
);
assert_eq!(preview.status, 200, "{}", preview.text());
let value: Value = serde_json::from_slice(&preview.body).expect("preview JSON");
let svg = value["pages"][0]["svg"].as_str().unwrap();
assert!(svg.contains("font-style=\"italic\""), "{svg}");
assert!(!svg.contains('$'), "{svg}");
let forced = server.request(
"POST",
"/api/projects/hello/preview?engine=v1",
&[],
"application/json",
);
assert_eq!(forced.status, 200, "{}", forced.text());
let value: Value = serde_json::from_slice(&forced.body).expect("preview JSON");
let svg = value["pages"][0]["svg"].as_str().unwrap();
assert!(svg.contains("TexrraSerif"), "{svg}");
}
#[test]
fn project_preview_expands_local_class_files() {
let server = TestServer::start("route-d-class");