diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index b372af9..de8fba6 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -1837,6 +1837,26 @@ mod tests { assert!(svg.contains("font-style=\"italic\">face2")); assert!(svg.contains("font-family=\"monospace\">face3")); } + + #[test] + fn display_list_paints_limits_above_and_below() { + let document = Document::new( + 1000, + vec![Unit::math( + 1, + crate::math::parse_math("\\sum_{i=1}^{n}"), + &Cmr10Metrics::default(), + )], + ); + let engine = Engine::layout(&document); + let list = engine.pages()[0].display_list(); + let texts = list + .items + .iter() + .filter(|item| matches!(item, DisplayItem::Text { .. })) + .count(); + assert!(texts >= 4, "expected sum plus both limits, got {texts}"); + } #[test] fn math_display_list_paints_symbols_and_fraction_rule() { let atom = crate::math::parse_math("x + \\frac{a}{b}"); diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index e2fead0..c9bc0df 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -682,9 +682,35 @@ impl Page { list, ); } + MathAtom::Limits { base, sub, sup } => { + let base_box = math::layout_math(base, font); + Self::paint_math(base, font, x, baseline, size, list); + let small = (size as f64 * 0.7) as i64; + if let Some(sup) = sup { + let sup_box = math::layout_math(sup, font); + Self::paint_math( + sup, + font, + x + (base_box.width - sup_box.width).max(0) / 2, + baseline - base_box.height - small, + small, + list, + ); + } + if let Some(sub) = sub { + let sub_box = math::layout_math(sub, font); + Self::paint_math( + sub, + font, + x + (base_box.width - sub_box.width).max(0) / 2, + baseline + base_box.depth + small, + small, + list, + ); + } + } MathAtom::Brace { base, .. } | MathAtom::Smash { body: base, .. } - | MathAtom::Limits { base, .. } | MathAtom::Classed { body: base, .. } => { Self::paint_math(base, font, x, baseline, size, list) }