From 484375fa2b05cbfa1f00c95ea8c46670441f843c Mon Sep 17 00:00:00 2001 From: GloamXun Date: Wed, 21 Oct 2026 01:28:42 +0800 Subject: [PATCH] Support absolute insertion class height limits --- crates/texrra-tex-core/src/lib.rs | 36 ++++++++++++++++++++++++++++++- docs/TEX_CORE.md | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 8613658..c4dffc0 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -518,6 +518,10 @@ impl Unit { pub struct InsertionClass { pub number: u8, pub fraction_percent: u8, + /// TeX's `\dimen`: an absolute cap on this class's height on one + /// page. `None` uses only the percentage share. + #[serde(default)] + pub max_height: Option, } #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] @@ -578,7 +582,10 @@ impl Document { .iter() .find(|entry| entry.number == class) .map_or(self.page_goal, |entry| { - self.page_goal * i64::from(entry.fraction_percent) / 100 + let fraction = self.page_goal * i64::from(entry.fraction_percent) / 100; + entry + .max_height + .map_or(fraction, |absolute| fraction.min(absolute)) }) } pub fn with_top_skip(mut self, top_skip: i64) -> Self { @@ -1666,6 +1673,7 @@ mod tests { document.insertion_classes = vec![InsertionClass { number: 1, fraction_percent: 30, + max_height: None, }]; let layout = Engine::layout(&document); assert_eq!(layout.pages().len(), 2); @@ -1691,10 +1699,12 @@ mod tests { InsertionClass { number: 1, fraction_percent: 60, + max_height: None, }, InsertionClass { number: 2, fraction_percent: 60, + max_height: None, }, ]; let layout = Engine::layout(&document); @@ -1703,6 +1713,30 @@ mod tests { assert_eq!(layout.pages()[1].insertions.len(), 1); } + #[test] + fn insertion_class_absolute_limit_caps_the_class_height() { + let rule = VerticalItem::Rule { + width: 65_536, + height: 100, + }; + let mut document = Document::new( + 1000, + vec![ + Unit::insertion(1, 1, 100, vec![rule.clone()]), + Unit::insertion(2, 1, 100, vec![rule]), + ], + ); + document.insertion_classes = vec![InsertionClass { + number: 1, + fraction_percent: 100, + max_height: Some(150), + }]; + let layout = Engine::layout(&document); + assert_eq!(layout.pages().len(), 2); + assert_eq!(layout.pages()[0].insertions.len(), 1); + assert_eq!(layout.pages()[1].insertions.len(), 1); + } + #[test] fn a_large_top_float_gets_a_float_page() { let mut document = Document::new(100, Vec::new()); diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index bbd171e..bb0bce8 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -267,7 +267,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 150 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 248 tests (150 route-D unit, 2 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 1 doctest). v1 remains the live server path. +The crate currently has 151 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 249 tests (151 route-D unit, 2 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 1 doctest). v1 remains the live server path. ### M0 incremental demo