From 12d8ae805b36841cd5c7e233654afec45c6a7eef Mon Sep 17 00:00:00 2001 From: GloamXun Date: Wed, 21 Oct 2026 01:18:02 +0800 Subject: [PATCH] Keep insertions from multiple classes within the page height --- crates/texrra-tex-core/src/lib.rs | 38 +++++++++++++++++++++++++++++++ docs/TEX_CORE.md | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index cdeda4b..8613658 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -914,6 +914,14 @@ impl Engine { } } VerticalItem::Insertion(insertion) => { + let capacity = document.page_goal.saturating_sub(document.top_skip).max(1); + if insertion_height + insertion.height > capacity + && (!current.items.is_empty() || !current.insertions.is_empty()) + { + pages.push(std::mem::replace(&mut current, Page::empty())); + used = document.top_skip; + insertion_height = 0; + } let class_limit = document .insertion_class_limit(insertion.class) .min(document.page_goal.saturating_sub(document.top_skip)) @@ -1665,6 +1673,36 @@ mod tests { assert_eq!(layout.pages()[1].insertions.len(), 1); } + #[test] + fn insertions_from_multiple_classes_respect_the_page_height() { + let rule = VerticalItem::Rule { + width: 65_536, + height: 60, + }; + let mut document = Document::new( + 100, + vec![ + Unit::insertion(1, 1, 60, vec![rule.clone()]), + Unit::insertion(2, 2, 60, vec![rule]), + ], + ); + document.top_skip = 0; + document.insertion_classes = vec![ + InsertionClass { + number: 1, + fraction_percent: 60, + }, + InsertionClass { + number: 2, + fraction_percent: 60, + }, + ]; + 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 2029443..bbd171e 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 149 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 246 tests (149 route-D unit, 2 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 doctest). v1 remains the live server path. +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. ### M0 incremental demo