diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 2c28c26..5b20799 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -300,6 +300,29 @@ impl Unit { Self::halign(id, rows, column_count, intercolumn) } + /// A running mark item, recorded on the page where it is shipped out. + pub fn mark(id: UnitId, class: u8, text: &str) -> Self { + Self::vertical( + id, + vec![VerticalItem::Mark(Mark { + class, + text: text.to_owned(), + })], + ) + } + + /// A top/bottom float item. + pub fn float(id: UnitId, placement: FloatPlacement, width: i64, height: i64) -> Self { + Self::vertical( + id, + vec![VerticalItem::Float(Float { + placement, + width, + height, + })], + ) + } + /// A vertical penalty item, corresponding to `\penalty`. pub fn penalty(id: UnitId, value: i64) -> Self { Self::vertical(id, vec![VerticalItem::Penalty(value)]) @@ -1227,6 +1250,27 @@ mod tests { assert_eq!(halign.cell_box(2, 0), Some((30, 110))); } + #[test] + fn mark_and_float_constructors_build_page_items() { + let document = Document::new( + 100, + vec![ + Unit::mark(1, 0, "Intro"), + Unit::float(2, FloatPlacement::Top, 50, 20), + Unit::vertical( + 3, + vec![VerticalItem::Box(VerticalBox { + width: 100, + height: 50, + })], + ), + ], + ); + let engine = Engine::layout(&document); + assert_eq!(engine.pages().len(), 1); + assert_eq!(engine.pages()[0].marks[0].text, "Intro"); + assert_eq!(engine.pages()[0].floats.len(), 1); + } #[test] fn forced_penalty_between_boxes_starts_a_page() { let block = |id| { diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 209beac..57fa06e 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -239,3 +239,5 @@ v1 remains the production renderer; the route-D core is additive and tested inde `\mathring{x}` is the U+030A ring accent. `\overleftrightarrow` uses U+20E1. + +`Unit::mark(id, class, text)` and `Unit::float(id, placement, width, height)` are convenience constructors for M2 page items.