Reserve the named TeX spaces in text

This commit is contained in:
gloamxun committed 2026-10-26 04:32:40 +08:00
1 parent 1e8b2367ca
commit c57de1e03c
3 files changed
+32 -3

No files matched your search

+29
View File
@@ -6955,6 +6955,10 @@ fn expand_ensuremath_plain(text: &str) -> String {
fn replace_spacing_commands(text: &str) -> String {
let mut out = text.to_string();
for (command, replacement) in [
("\\enspace", "\\hspace{0.5em}"),
("\\thinspace", "\\hspace{0.16667em}"),
("\\medspace", "\\hspace{0.22222em}"),
("\\thickspace", "\\hspace{0.27778em}"),
("\\qquad", "\\hspace{2em}"),
("\\quad", "\\hspace{1em}"),
("\\;", "\\hspace{0.27778em}"),
@@ -13194,6 +13198,31 @@ A definition.
assert_eq!(runs[0].3, "Boxed");
}
#[test]
fn named_spaces_reach_the_layout() {
let blocks = paragraphs("A\\enspace B").expect("paragraphs");
let document = build_document(&blocks, &PageGeometry::default());
let engine = Engine::layout(&document);
let mut positions = Vec::new();
let mut leaked = false;
for page in engine.pages() {
for item in page.display_list().items {
if let texrra_tex_core::render::DisplayItem::Text { text, x, .. } = item {
if text == "e" {
leaked = true;
}
if text == "A" || text == "B" {
positions.push((text, x));
}
}
}
}
let a = positions.iter().find(|(text, _)| text == "A").expect("A").1;
let b = positions.iter().find(|(text, _)| text == "B").expect("B").1;
assert!(b - a > 400_000, "gap {}", b - a);
assert!(!leaked);
}
#[test]
fn quad_commands_become_text_spaces() {
let blocks = paragraphs("A\\quad B").expect("paragraphs");