Centre centerline arguments

This commit is contained in:
gloamxun committed 2026-10-26 04:45:58 +08:00
1 parent f11561f15f
commit 9aa7198aed
3 files changed
+27 -2

No files matched your search

+25
View File
@@ -9299,6 +9299,12 @@ fn build_document_with_labels(
ragged = true;
text = rest.trim_start().to_string();
}
if let Some(rest) = text.trim_start().strip_prefix("\\centerline") {
if let Some((body, used)) = braced_group(rest.trim_start()) {
centered = true;
text = format!("{}{}", body, &rest.trim_start()[used..]);
}
}
let trimmed = text.trim_start();
if let Some(rest) = trimmed.strip_prefix("\\centering") {
centered = true;
@@ -13396,6 +13402,25 @@ A definition.
assert_eq!(blocks[0].text, "See In body.");
}
#[test]
fn centerline_centres_its_argument() {
let blocks = paragraphs("\\centerline{Short.}").expect("paragraphs");
let document = build_document(&blocks, &PageGeometry::default());
let engine = Engine::layout(&document);
let x = engine
.pages()
.iter()
.flat_map(|page| page.display_list().items)
.find_map(|item| match item {
texrra_tex_core::render::DisplayItem::Text { text, x, .. } if text == "S" => {
Some(x)
}
_ => None,
})
.expect("S glyph");
assert!(x > 0, "centerline text starts at {}", x);
}
#[test]
fn raggedright_declaration_keeps_lines_short() {
let blocks = paragraphs("\\raggedright A line of text.").expect("paragraphs");