diff --git a/crates/texrra-tex-core/src/paragraph.rs b/crates/texrra-tex-core/src/paragraph.rs index f10c92f..86089aa 100755 --- a/crates/texrra-tex-core/src/paragraph.rs +++ b/crates/texrra-tex-core/src/paragraph.rs @@ -45,6 +45,8 @@ pub struct ParagraphStyle { /// Center each line in the measure instead of justifying it. #[serde(default)] pub centered: bool, + #[serde(default)] + pub right_aligned: bool, pub par_indent: i64, pub line_height: i64, pub char_width: i64, @@ -60,6 +62,7 @@ impl Default for ParagraphStyle { left_skip: 0, right_skip: 0, centered: false, + right_aligned: false, par_indent: 0, line_height: 12, char_width: 10, @@ -97,6 +100,8 @@ pub struct Paragraph { pub left_skip: i64, #[serde(default)] pub centered: bool, + #[serde(default)] + pub right_aligned: bool, } impl Paragraph { @@ -157,6 +162,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra font: ParagraphFont::Roman, left_skip: style.left_skip, centered: style.centered, + right_aligned: style.right_aligned, }; } let mut breakpoints = vec![0_usize]; @@ -334,6 +340,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra font: ParagraphFont::Roman, left_skip: style.left_skip, centered: style.centered, + right_aligned: style.right_aligned, } } diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index 517fd6f..4f05d6f 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -389,6 +389,8 @@ impl Page { .sum(); let mut x = if paragraph.centered { paragraph.left_skip + ((paragraph.width - natural) / 2).max(0) + } else if paragraph.right_aligned { + paragraph.left_skip + (paragraph.width - natural).max(0) } else { paragraph.left_skip }; diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 5e70f28..2c798b1 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -234,7 +234,7 @@ for a later overlaid slash. | 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; only faces used on a page are embedded, and ASCII documents use the 110-glyph minimal tier (one-page Roman PDF is about 21 KB); 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 with content-based page hashes and section/emphasis/display-math/itemize/enumerate/description/quote/center mapping; editor integration and inline math pending | +| M7 incremental integration | partial | route-D preview/PDF/edit endpoints with content-based page hashes and section/emphasis/display-math/itemize/enumerate/description/quote/center/flushright mapping; editor integration and inline math pending | v1 remains the production renderer; the route-D core is additive and tested independently. @@ -264,7 +264,7 @@ M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row hei 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. -The crate currently has 138 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 233 tests (139 route-D unit, 1 route-D integration, 71 v1 integration, 17 server, 4 v1 unit, 1 doctest). v1 remains the live server path. +The crate currently has 138 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 234 tests (139 route-D unit, 1 route-D integration, 71 v1 integration, 18 server, 4 v1 unit, 1 doctest). v1 remains the live server path. ### M0 incremental demo diff --git a/src/route_d.rs b/src/route_d.rs index 9abd35e..f2c1b46 100755 --- a/src/route_d.rs +++ b/src/route_d.rs @@ -79,6 +79,7 @@ pub fn edit_json(source: &str, unit: usize) -> Result { struct SourceParagraph { text: String, centered: bool, + right_aligned: bool, font: ParagraphFont, line_height: i64, math: bool, @@ -132,6 +133,7 @@ fn parse_blocks(raw: &str) -> Vec { math: false, left_skip: 12, centered: false, + right_aligned: false, } }) .collect(); @@ -152,6 +154,7 @@ fn parse_blocks(raw: &str) -> Vec { math: false, left_skip: 12, centered: false, + right_aligned: false, }]; } } @@ -181,6 +184,7 @@ fn parse_blocks(raw: &str) -> Vec { math: false, left_skip: 12, centered: false, + right_aligned: false, } }) .collect(); @@ -210,6 +214,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph { math: true, left_skip: 0, centered: false, + right_aligned: false, }; } let candidates = [ @@ -226,6 +231,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph { math: false, left_skip: 0, centered: false, + right_aligned: false, }; } } @@ -236,6 +242,7 @@ fn parse_paragraph(raw: &str) -> SourceParagraph { math: false, left_skip: 0, centered: false, + right_aligned: false, } } @@ -255,6 +262,7 @@ fn build_document(paragraphs: &[SourceParagraph]) -> Document { line_width: 480 * SCALE, left_skip: paragraph.left_skip * SCALE, centered: paragraph.centered, + right_aligned: paragraph.right_aligned, right_skip: 0, par_indent: 0, line_height: paragraph.line_height * SCALE, diff --git a/tests/server.rs b/tests/server.rs index 4fd5363..9b74ff4 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -554,6 +554,30 @@ fn route_d_renders_center_blocks() { assert!(x > 50.0, "{x}"); } +#[test] +fn route_d_renders_flushright_blocks() { + let server = TestServer::start("route-d-flushright"); + let response = server.request( + "POST", + "/api/route-d/preview", + b"\\begin{flushright}Right\\end{flushright}", + "text/plain", + ); + assert_eq!(response.status, 200, "{}", response.text()); + let value: Value = serde_json::from_slice(&response.body).expect("route-D JSON"); + let svg = value["pages"][0]["svg"].as_str().unwrap(); + let index = svg.find(">R").expect("right R"); + let prefix = &svg[..index]; + let start = prefix.rfind(" 100.0, "{x}"); +} + #[test] fn edits_route_d_preview_pages() { let server = TestServer::start("route-d-edit");