Support multicolumn spans and partial table rules

This commit is contained in:
gloamxun committed 2026-10-19 17:53:26 +08:00
1 parent ca5cb0b8af
commit d4e52dc225
13 files changed
+698 -187

No files matched your search

+71
View File
@@ -1050,6 +1050,77 @@ fn arxiv_table_rules_follow_a_narrow_centered_table() {
);
}
#[test]
fn multicolumn_and_cmidrule_render_spans() {
let source = r"\documentclass{article}
\begin{document}
\begin{tabular}{lll}
\toprule
\multicolumn{2}{c}{Part} \\
\cmidrule(r){1-2}
Name & Description & Size ($\mu$m) \\
\midrule
Dendrite & Input terminal & 100 \\
\bottomrule
\end{tabular}
\end{document}";
let value = fresh_preview(source, "multicolumn.tex");
assert_eq!(value["status"], "ok", "{}", value["message"]);
let svg = page_svg(&value, 0);
let mut rules = Vec::new();
for fragment in svg.split("<line ").skip(1) {
let tag = fragment.split('>').next().unwrap_or(fragment);
let read = |name: &str| {
tag.split(&format!("{name}=\""))
.nth(1)
.and_then(|rest| rest.split('"').next())
.and_then(|value| value.parse::<f64>().ok())
};
if let (Some(x1), Some(x2), Some(y1), Some(y2)) =
(read("x1"), read("x2"), read("y1"), read("y2"))
&& x2 > x1 + 10.0
&& (y1 - y2).abs() < 0.01
{
rules.push((x1, x2, y1));
}
}
assert_eq!(rules.len(), 4, "expected four table rules, got {rules:?}");
let full = rules
.iter()
.max_by(|left, right| (left.1 - left.0).total_cmp(&(right.1 - right.0)))
.copied()
.expect("full-width rule");
let short = rules
.iter()
.find(|(x1, x2, _)| *x2 - *x1 < (full.1 - full.0) * 0.9)
.copied()
.expect("partial cmidrule");
assert!(
(short.0 - full.0).abs() < 1.0,
"partial rule should start at the first column: {short:?}"
);
assert!(
short.1 < full.1 - 5.0,
"partial rule extends across the whole table: {short:?}"
);
let mut part_x = None;
for fragment in svg.split("<text ").skip(1) {
let tag = fragment.split('>').next().unwrap_or(fragment);
if fragment.contains(">Part</text>") {
part_x = tag
.split("x=\"")
.nth(1)
.and_then(|rest| rest.split('"').next())
.and_then(|value| value.parse::<f64>().ok());
}
}
let part_x = part_x.expect("Part text in SVG");
assert!(
part_x < full.0 + (full.1 - full.0) / 2.0,
"multicolumn text should be centered over the first two columns, Part x={part_x}, rule={full:?}"
);
}
#[test]
fn abstract_environment_gets_an_unumbered_heading() {
let source = r"\documentclass{article}