From b17e16df08307d7e00690d8a77836afa16ea9996 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 13:25:06 +0800 Subject: [PATCH] Add a vskip constructor for vertical glue --- crates/texrra-tex-core/src/lib.rs | 20 ++++++++++++++++++++ docs/TEX_CORE.md | 2 ++ 2 files changed, 22 insertions(+) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 304df90..fbc59a4 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 glue item, corresponding to `\vskip`. + pub fn vskip(id: UnitId, height: i64) -> Self { + Self::vertical(id, vec![VerticalItem::Glue(height)]) + } + /// A filled rule in the vertical list. pub fn rule(id: UnitId, width: i64, height: i64) -> Self { Self::vertical(id, vec![VerticalItem::Rule { width, height }]) @@ -1217,6 +1222,21 @@ mod tests { assert_eq!(halign.cell_box(2, 0), Some((30, 110))); } + #[test] + fn vskip_consumes_vertical_space() { + let block = |id| { + Unit::vertical( + id, + vec![VerticalItem::Box(VerticalBox { + width: 100, + height: 30, + })], + ) + }; + let document = Document::new(50, vec![block(1), Unit::vskip(2, 10), block(3)]); + let engine = Engine::layout(&document); + assert_eq!(engine.pages().len(), 2); + } #[test] fn vertical_rules_consume_page_height() { let unit = Unit::rule(1, 100, 60); diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index cffc24e..245b346 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -208,3 +208,5 @@ for a later overlaid slash. `\mathinner{...}` uses `MathClass::Inner` with 3mu on either side. `\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.