diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index fbc59a4..2c28c26 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -300,6 +300,11 @@ impl Unit { Self::halign(id, rows, column_count, intercolumn) } + /// A vertical penalty item, corresponding to `\penalty`. + pub fn penalty(id: UnitId, value: i64) -> Self { + Self::vertical(id, vec![VerticalItem::Penalty(value)]) + } + /// A vertical glue item, corresponding to `\vskip`. pub fn vskip(id: UnitId, height: i64) -> Self { Self::vertical(id, vec![VerticalItem::Glue(height)]) @@ -1222,6 +1227,21 @@ mod tests { assert_eq!(halign.cell_box(2, 0), Some((30, 110))); } + #[test] + fn forced_penalty_between_boxes_starts_a_page() { + let block = |id| { + Unit::vertical( + id, + vec![VerticalItem::Box(VerticalBox { + width: 100, + height: 30, + })], + ) + }; + let document = Document::new(100, vec![block(1), Unit::penalty(2, -10_000), block(3)]); + let engine = Engine::layout(&document); + assert_eq!(engine.pages().len(), 2); + } #[test] fn vskip_consumes_vertical_space() { let block = |id| { diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 245b346..03f6b07 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -210,3 +210,5 @@ for a later overlaid slash. `\boxed{x}` adds 3pt padding around its body in the math model. `Unit::vskip(id, height)` adds a vertical glue item to the page list. + +`Unit::penalty(id, value)` adds a vertical penalty; values <= -10000 force a page break.