Keep sum superscripts above the operator

Large-operator limits used the ordinary-base superscript gap, which could
leave N just below the sum baseline. Use a negative gap for large operators
so both limits straddle the operator, and add a unit test asserting the
subscript is below and the superscript above the base within 12pt.

Test count is 1080.
This commit is contained in:
gloamxun committed 2026-10-28 08:28:17 +08:00
1 parent 02742d201f
commit 676eb7f323
6 files changed
+41 -8

No files matched your search

+28
View File
@@ -3912,6 +3912,34 @@ mod tagged_equation_tests {
assert_eq!(tagged.height, plain.height.max(7 * 65_536));
assert_eq!(tagged.depth, plain.depth.max(2 * 65_536));
}
#[test]
fn display_sum_limits_sit_close_to_the_operator() {
let atom = parse_math(r"\sum_{i=1}^{N}");
let unit = crate::Unit::math(1, atom, &Cmr10Metrics::default());
let document = crate::Document::new(700 * 65_536, vec![unit]);
let engine = crate::Engine::layout(&document);
let display = engine.pages()[0].display_list();
let find = |text: &str| {
display
.items
.iter()
.find_map(|item| match item {
crate::render::DisplayItem::Text { text: value, y, .. } if value == text => {
Some(*y)
}
_ => None,
})
.unwrap_or_else(|| panic!("no {text} glyph"))
};
let base = find("∑");
let sub = find("i");
let sup = find("N");
assert!(sub > base, "subscript {sub} above base {base}");
assert!(sup < base, "superscript {sup} below base {base}");
let gap = (sub - base) as f64 / 65_536.0;
assert!(gap < 12.0, "sum limit gap {gap} pt");
}
#[test]
fn whitespace_before_a_script_still_attaches() {
let atom = parse_math(r"\alpha _{i}");