From e2e80e87289316b76e11c49805130058e1b2885a Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 27 Oct 2026 21:01:24 +0800 Subject: [PATCH] Compile editor buffers without waiting for a save Project preview accepts ?buffer=1 and reads the editor text from the POST body. The source is still expanded with project includes/packages/images, but the file on disk is not touched, so typing can drive layout immediately while the normal 450 ms save timer runs independently. Add a server test that previews buffer text, finds it in the SVG, and verifies hello.tex on disk was not rewritten. Roadmap notes that warm buffer previews are still ~430 ms (article) and ~2.1 s (arXiv), and that dirty-page streaming is the next latency step. --- docs/ROUTE_D_PLAN.md | 2 +- docs/ROUTE_D_STATUS.md | 6 +++--- docs/TEX_CORE.md | 4 ++-- docs/TEX_FIDELITY_ROADMAP.md | 9 +++++++-- docs/WEB_ROUTE_D_EXPERIMENT.md | 2 +- src/main.rs | 14 +++++++++++++- tests/server.rs | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 61 insertions(+), 10 deletions(-) diff --git a/docs/ROUTE_D_PLAN.md b/docs/ROUTE_D_PLAN.md index c29bd6a..3809d86 100644 --- a/docs/ROUTE_D_PLAN.md +++ b/docs/ROUTE_D_PLAN.md @@ -51,7 +51,7 @@ floats (`\floatsep`, `\textfloatsep`, `\intextsep`, `\topfraction`, 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` and project previews now -prefer route-D with a v1 fallback). 1070 workspace tests are green and no oracle +prefer route-D with a v1 fallback). 1071 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. diff --git a/docs/ROUTE_D_STATUS.md b/docs/ROUTE_D_STATUS.md index 503efa4..986c410 100755 --- a/docs/ROUTE_D_STATUS.md +++ b/docs/ROUTE_D_STATUS.md @@ -16,20 +16,20 @@ cargo test --workspace --offline or run `./scripts/verify-route-d.sh`, which executes both. -The workspace currently passes **1070 tests**: +The workspace currently passes **1071 tests**: | Suite | Tests | | --- | --- | | route-D unit (engine) | 444 | | engine binary unit | 433 | -| server integration | 65 | +| server integration | 66 | | v1 integration | 71 | | pdfLaTeX oracle | 42 | | route-D integration | 10 | | engine/core unit | 4 + 1 | Latest full run (web trial increment): `./scripts/verify-route-d.sh` passes -with fmt clean and **1070 tests** green. +with fmt clean and **1071 tests** green. Latest live check (2026-10-27): the debug server served `examples/hello.tex` from `target/debug/texrra serve`; `POST /preview` answered 200 with diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 093f021..0f1bf63 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -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 444 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1070 tests (444 core unit, 433 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 65 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; flat and project responses carry `X-Preview-Engine`, naming the engine used). A geometry-less project now defaults to Letter, matching pdfLaTeX, where the old v1 path used A4. +The crate currently has 444 unit tests plus ten route-D integration tests and forty-two oracle fixtures. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 1071 tests (444 core unit, 433 engine binary unit, 10 route-D integration, 42 oracle, 71 v1 integration, 66 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; flat and project responses carry `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 @@ -524,7 +524,7 @@ deliberately open rather than approximated: ## Limits and remaining gaps -The suite currently stands at 1070 passing tests, with the workspace clean. +The suite currently stands at 1071 passing tests, with the workspace clean. Route-D serves both flat `/preview` and project preview/PDF requests by default (automatic v1 fallback; `?engine=v1` or `TEXRRA_ENGINE=v1` opts out). The objective's areas are implemented to the limits below; complex-script shaping is diff --git a/docs/TEX_FIDELITY_ROADMAP.md b/docs/TEX_FIDELITY_ROADMAP.md index 2caaf8e..18fbcb9 100644 --- a/docs/TEX_FIDELITY_ROADMAP.md +++ b/docs/TEX_FIDELITY_ROADMAP.md @@ -49,11 +49,16 @@ execution is not a goal. - project-scoped sessions and changed-page reporting; - web `applyPages` skips pages whose hash is unchanged; - a 90 ms preview debounce and 450 ms save debounce. +- Incremental progress in the working tree: + - project previews accept `?buffer=1` with the editor text as the request + body, so preview no longer waits for the 450 ms disk save; + - the web editor previews on a 40 ms debounce while saving on the old timer; + - `changedPages` already identifies the pages that need repainting. - Incremental bottlenecks: - the server still returns every page's SVG JSON; - the browser downloads all pages before hash-skipping; - - project edits wait for the save timer before preview; - - the arxiv project's preview/layout is still in the 1.4–1.5 s range; + - measured warm buffer previews are still about 430 ms for article-basic + and 2.1 s for the arXiv template; the <100 ms target is not met; - no WebSocket/SSE stream or dirty-page patch protocol. ## Architecture diff --git a/docs/WEB_ROUTE_D_EXPERIMENT.md b/docs/WEB_ROUTE_D_EXPERIMENT.md index 15c322d..bf876d5 100644 --- a/docs/WEB_ROUTE_D_EXPERIMENT.md +++ b/docs/WEB_ROUTE_D_EXPERIMENT.md @@ -46,7 +46,7 @@ now means route-D. | Area | Route-D | Evidence / impact | | --- | --- | --- | -| Article/report basics: title, sections, lists, TOC, page numbers | Supported | corpus and 1070-test suite | +| Article/report basics: title, sections, lists, TOC, page numbers | Supported | corpus and 1071-test suite | | Inline/display math, equations, tags, cleveref | Supported | math tests, oracle fixtures | | Floats, captions, tables, booktabs | Supported | table/math tests, corpus | | PNG/JPEG/BMP `\includegraphics` | Supported | project image tests | diff --git a/src/main.rs b/src/main.rs index 0d0a188..e98dd25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1532,10 +1532,22 @@ fn handle_project_request( } } (&Method::Post, [id, "preview"]) => { - let (source, file_name) = match store.main_source(id) { + let (mut source, file_name) = match store.main_source(id) { Ok(source) => source, Err(error) => return respond_api_error(request, 422, &error), }; + if query_param(url, "buffer").is_some() { + let bytes = match read_body_bytes(&mut request, MAX_SOURCE_BYTES) { + Ok(bytes) => bytes, + Err(error) => return respond_api_error(request, 413, &error), + }; + source = match String::from_utf8(bytes) { + Ok(source) => source, + Err(_) => { + return respond_api_error(request, 400, "preview buffer is not UTF-8"); + } + }; + } if uses_route_d(url) { let expanded = expand_project_source(&source, &store, id); let images = load_project_images(&expanded, &store, id); diff --git a/tests/server.rs b/tests/server.rs index 4f46eac..310d450 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -1258,6 +1258,40 @@ fn project_preview_resolves_bibtex() { assert!(!text.contains("[?]"), "{text}"); } +#[test] +fn project_preview_compiles_the_editor_buffer_without_saving() { + let server = TestServer::start("route-d-buffer"); + let buffer = + "\\documentclass{article}\n\\begin{document}\n\nBuffer preview.\n\n\\end{document}\n"; + let preview = server.request( + "POST", + "/api/projects/hello/preview?engine=route-d&buffer=1", + buffer.as_bytes(), + "text/plain; charset=utf-8", + ); + assert_eq!(preview.status, 200, "{}", preview.text()); + let value: Value = serde_json::from_slice(&preview.body).expect("preview JSON"); + assert_eq!(value["status"], "ok", "{}", value["message"]); + let mut text = String::new(); + for page in value["pages"].as_array().expect("pages") { + if let Some(svg) = page["svg"].as_str() { + for piece in svg.split('>') { + if let Some(content) = piece.split('<').next() { + text.push_str(content); + } + } + } + } + let text: String = text.split_whitespace().collect(); + assert!(text.contains("Bufferpreview"), "{text}"); + let raw = server.get("/api/projects/hello/raw?path=hello.tex"); + assert_eq!(raw.status, 200); + assert!( + !raw.text().contains("Buffer preview"), + "buffer preview must not write the file" + ); +} + #[test] fn project_preview_can_switch_to_route_d() { let server = TestServer::start("route-d-toggle");