Default project previews and PDFs to route-D

uses_route_d still treated v1 as the default unless TEXRRA_ENGINE=route-d was
set, so only the flat /preview endpoint had switched. Make route-D the default
there too: an explicit engine parameter still wins, TEXRRA_ENGINE=v1 forces the
old pipeline, and a route-D error now falls through to the v1 compiler instead
of answering 422 (both preview and PDF).

Because route-D follows pdfLaTeX's Letter default for geometry-less documents,
the two server tests that asserted the v1 A4 page now ask for ?engine=v1 or
expect 215.9mm. A new test starts a server without the environment variable and
checks a project preview uses route-D's italic math face with no literal $.
This commit is contained in:
gloamxun committed 2026-10-27 00:32:45 +08:00
1 parent a56d441513
commit 371f05baaa
4 files changed
+48 -23

No files matched your search

+5 -5
View File
@@ -48,8 +48,8 @@ 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`; flat `/preview` now prefers route-D with a v1
fallback). 993 workspace tests are green and no oracle
PDF opt-in with `?engine=route-d`; flat `/preview` and project previews now
prefer route-D with a v1 fallback). 994 workspace tests are green and no oracle
fixture is ignored. Preview JSON also carries a `warnings` array naming
environments route-D cannot lay out and control words that survived layout, so
unsupported source is reported instead of being silently typeset.
@@ -492,9 +492,9 @@ Each goal keeps `cargo fmt`, `cargo test`, `cargo build --release` green, update
## Handoff (round 150/150)
Route-D currently passes **928** workspace tests and is pushed at `b191f7d`.
The flat `/preview` endpoint now tries route-D first and falls back to v1 (pass
`?engine=v1` to force v1); project previews still select route-D with
`?engine=route-d` or `TEXRRA_ENGINE=route-d`. To continue the programme:
The flat `/preview` and project preview/PDF endpoints now try route-D first
and fall back to v1 (pass `?engine=v1` or set `TEXRRA_ENGINE=v1` for the old
pipeline). To continue the programme:
1. Run `cargo fmt --all -- --check` and `cargo test --workspace --offline`
from `engine/` before every change; pdfLaTeX oracles skip automatically when
+5 -5
View File
@@ -370,7 +370,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; those fallback glyphs keep their Unicode text under PDF extraction, so accented and Greek words round-trip; Type1 faces carry a ToUnicode CMap built from the requested characters, so glyphs whose names are ambiguous in the Adobe Glyph List (capital Omega, which would otherwise extract as U+2126) keep their intended code points. `Engine::edit` preserves the face when reflowing an edited paragraph.
The crate currently has 437 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 993 tests (437 route-D unit, 367 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 61 server, 4 engine unit, 1 core unit), with none ignored. The flat `/preview` endpoint now tries route-D first and falls back to v1 on error (`?engine=v1` forces v1; the `X-Preview-Engine` response header names the engine used), while the project preview/PDF endpoints still follow `TEXRRA_ENGINE`.
The crate currently has 437 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 994 tests (437 route-D unit, 367 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 62 server, 4 engine unit, 1 core unit), with none ignored. The flat `/preview` endpoint and the project preview/PDF endpoints now try route-D first and fall back to v1 on error (`?engine=v1` or `TEXRRA_ENGINE=v1` forces v1; the flat response carries `X-Preview-Engine`, naming the engine used). A geometry-less project now defaults to Letter, matching pdfLaTeX, where the old v1 path used A4.
### M0 incremental demo
@@ -521,10 +521,10 @@ deliberately open rather than approximated:
## Remaining gaps at round 148
The suite currently stands at 928 passing tests, with the workspace clean.
Route-D now serves flat `/preview` requests by default (automatic v1 fallback,
`?engine=v1` opt-out), while project previews still follow
`?engine=route-d`/`TEXRRA_ENGINE`. The honest open items against the
"feature-complete LaTeX compiler" objective are:
Route-D now serves both flat `/preview` and project preview/PDF requests by
default (automatic v1 fallback; `?engine=v1` or `TEXRRA_ENGINE=v1` opts out).
The honest open items against the "feature-complete LaTeX compiler" objective
are:
- **Macro engine scope**: `\def`-style definitions, registers, conditionals,
`\csname`, `\expandafter`, delimited parameters and `\edef` are executed
+12 -11
View File
@@ -1299,13 +1299,13 @@ fn handle_project_request(
if let Some(json) = route_d_cached_preview(&key) {
return respond_json(request, 200, &preview_without_changes(&json));
}
return match route_d::project_preview_json_with_images(id, &expanded, &images) {
match route_d::project_preview_json_with_images(id, &expanded, &images) {
Ok(json) => {
store_route_d_preview(key, json.clone());
respond_json(request, 200, &json)
return respond_json(request, 200, &json);
}
Err(error) => respond_api_error(request, 422, &error),
};
Err(_) => {}
}
}
match compiler.preview_json(&source, &file_name) {
Ok(json) => respond_json(request, 200, &json),
@@ -1329,13 +1329,13 @@ fn handle_project_request(
if let Some(pdf) = route_d_cached_pdf(&key) {
return respond_pdf_with_cache(request, pdf, "hit");
}
return match route_d::pdf_bytes_with_images(&expanded, &images) {
match route_d::pdf_bytes_with_images(&expanded, &images) {
Ok(pdf) => {
store_route_d_pdf(key, &pdf);
respond_pdf_with_cache(request, pdf, "miss")
return respond_pdf_with_cache(request, pdf, "miss");
}
Err(error) => respond(request, 422, "text/plain; charset=utf-8", &error),
};
Err(_) => {}
}
}
match compiler.compile(&source, &file_name) {
Ok(pdf) => respond_pdf(request, pdf),
@@ -1384,14 +1384,15 @@ 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.
/// wins, then `TEXRRA_ENGINE=v1` forces the old pipeline, and route-D is the
/// default (with a v1 fallback when route-D rejects the source).
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),
.map(|engine| engine != "v1")
.unwrap_or(true),
}
}
+26 -2
View File
@@ -1143,7 +1143,7 @@ fn serves_project_api_preview_and_pdf() {
let value: Value = serde_json::from_slice(&preview.body).expect("preview JSON");
assert_eq!(value["status"], "ok", "{}", value["message"]);
assert_eq!(value["pages"].as_array().map(Vec::len), Some(1));
assert!((value["pageWidthMm"].as_f64().unwrap() - 210.0).abs() < 0.1);
assert!((value["pageWidthMm"].as_f64().unwrap() - 215.9).abs() < 0.1);
let pdf = server.request("POST", "/api/projects/hello/pdf", &[], "application/pdf");
assert_eq!(pdf.status, 200, "{}", String::from_utf8_lossy(&pdf.body));
@@ -1232,7 +1232,7 @@ fn project_preview_can_switch_to_route_d() {
let v1 = server.request(
"POST",
"/api/projects/hello/preview",
"/api/projects/hello/preview?engine=v1",
&[],
"application/json",
);
@@ -2320,3 +2320,27 @@ fn preview_uses_route_d_by_default_and_v1_on_request() {
assert_eq!(v1.status, 200, "{}", v1.text());
assert_eq!(v1.header("X-Preview-Engine"), Some("v1"));
}
#[test]
fn project_preview_defaults_to_route_d_without_env() {
let server = TestServer::start("project-default-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}");
}