Honour vspace as paragraph glue

This commit is contained in:
gloamxun committed 2026-10-24 23:39:53 +08:00
1 parent 32ca78bff5
commit a9614ccee2
4 files changed
+26 -7

No files matched your search

+20 -3
View File
@@ -1741,9 +1741,15 @@ fn vertical_skip(text: &str) -> Option<(i64, i64, i64)> {
"\\smallskip" => Some((3 * SCALE, SCALE, SCALE)),
"\\medskip" => Some((6 * SCALE, 2 * SCALE, 2 * SCALE)),
"\\bigskip" => Some((12 * SCALE, 4 * SCALE, 4 * SCALE)),
other => other
.strip_prefix("\\vskip")
.and_then(|rest| skip_glue(rest.trim_start())),
other => {
if let Some(rest) = other.strip_prefix("\\vskip") {
return skip_glue(rest.trim_start());
}
let rest = other.strip_prefix("\\vspace")?.trim_start();
let rest = rest.strip_prefix('*').map(str::trim_start).unwrap_or(rest);
let (argument, _) = braced_group(rest)?;
skip_glue(&argument)
}
}
}
@@ -5976,6 +5982,17 @@ A definition.
);
}
#[test]
fn vspace_between_paragraphs_sets_vertical_glue() {
let source = "A.\n\n\\vspace{7pt plus 1pt minus 2pt}\n\nB.\n\n\\vspace*{2mm}\n\nC.";
let blocks = paragraphs(source).expect("paragraphs");
assert_eq!(blocks[1].space_before, 7 * SCALE);
assert_eq!(blocks[1].space_stretch, SCALE);
assert_eq!(blocks[1].space_shrink, 2 * SCALE);
assert!((blocks[2].space_before - 2 * 186_468).abs() <= 1);
assert!(!blocks.iter().any(|block| block.text.contains("vspace")));
}
#[test]
fn paragraphs_read_vertical_skip_commands() {
let source = "Alpha.\n\n\\medskip\n\nBeta.\n\n\\bigskip\n\nGamma.\n\n\\vskip 5pt plus 2pt minus 1pt\n\nDelta.";