diff --git a/src/elements/msubsup.rs b/src/elements/msubsup.rs index e29f124..e07c9ce 100644 --- a/src/elements/msubsup.rs +++ b/src/elements/msubsup.rs @@ -6,7 +6,7 @@ use crate::{ Element, Elements, }; -use super::IntoElements; +use super::{grouping::Row, IntoElements}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] enum SubSupInner { @@ -72,6 +72,12 @@ pub struct SubSupBuilder { impl SubSupBuilder { /// Set the base of the [`SubSup`] element. pub fn base(self, base: impl IntoElements) -> SubSupBuilder { + let mut base = base.into_elements(); + + if base.len() > 1 { + base = Row::from(base).into_elements(); + } + SubSupBuilder { base: Some(base.into_elements()), sub: self.sub, @@ -83,6 +89,12 @@ impl SubSupBuilder { /// Set the subscript of the [`SubSup`] element. pub fn subscript(self, sub: impl IntoElements) -> SubSupBuilder { + let mut sub = sub.into_elements(); + + if sub.len() > 1 { + sub = Row::from(sub).into_elements(); + } + SubSupBuilder { base: self.base, sub: Some(sub.into_elements()), @@ -94,6 +106,12 @@ impl SubSupBuilder { /// Set the superscript of the [`SubSup`] element. pub fn supscript(self, sup: impl IntoElements) -> SubSupBuilder { + let mut sup = sup.into_elements(); + + if sup.len() > 1 { + sup = Row::from(sup).into_elements(); + } + SubSupBuilder { base: self.base, sub: self.sub, @@ -132,8 +150,10 @@ impl SubSupBuilder { } }; + let base = self.base.expect("Base is guaranteed to be init."); + SubSup { - base: self.base.expect("Base is guaranteed to be init."), + base, inner, attributes: self.attr, } diff --git a/src/elements/munderover.rs b/src/elements/munderover.rs index 3730d5f..7da3e9b 100644 --- a/src/elements/munderover.rs +++ b/src/elements/munderover.rs @@ -99,6 +99,12 @@ pub struct UnderOverBuilder { impl UnderOverBuilder { /// Set the base expression of the [`UnderOver`] element. pub fn expr(self, expr: impl IntoElements) -> UnderOverBuilder { + let mut expr = expr.into_elements(); + + if expr.len() > 1 { + expr = Row::from(expr).into_elements(); + } + UnderOverBuilder { expr: Some(expr.into_elements()), under: self.under, @@ -111,6 +117,12 @@ impl UnderOverBuilder { /// Set the under script of the [`UnderOver`] element. pub fn over(self, over: impl IntoElements) -> UnderOverBuilder { + let mut over = over.into_elements(); + + if over.len() > 1 { + over = Row::from(over).into_elements(); + } + UnderOverBuilder { expr: self.expr, under: self.under, @@ -122,6 +134,12 @@ impl UnderOverBuilder { /// Set the over script of the [`UnderOver`] element. pub fn under(self, under: impl IntoElements) -> UnderOverBuilder { + let mut under = under.into_elements(); + + if under.len() > 1 { + under = Row::from(under).into_elements(); + } + UnderOverBuilder { expr: self.expr, under: Some(under.into_elements()), @@ -160,11 +178,7 @@ impl UnderOverBuilder { } }; - let mut expr = self.expr.expect("Expr is guaranteed to be init."); - - if expr.len() > 1 { - expr = Row::from(expr).into_elements(); - } + let expr = self.expr.expect("Expr is guaranteed to be init."); UnderOver { expr, diff --git a/tests/scripted/mod.rs b/tests/scripted/mod.rs index 8608d0d..d657d89 100644 --- a/tests/scripted/mod.rs +++ b/tests/scripted/mod.rs @@ -16,6 +16,28 @@ fn subsup() { crate::snap_test!(out, name: "subsup_subsup"); } +#[test] +fn subsup_many() { + let sub = alemat::children![ + Operator::lparens(), + Ident::from("n"), + Operator::eq(), + Num::from(0), + Operator::rparens(), + ]; + + let sup = alemat::children![Ident::from("k"), Operator::plus(), Num::from(1)]; + + let out = MathMl::with_content(alemat::children![SubSup::builder() + .base(Operator::integral()) + .subscript(sub) + .supscript(sup) + .build()]) + .render(); + + crate::snap_test!(out, name: "subsup_many"); +} + #[test] fn subsup_integral() { let out = MathMl::with_content(alemat::children![ @@ -66,6 +88,28 @@ fn underover() { crate::snap_test!(out, name: "underover_underover"); } +#[test] +fn underover_many() { + let under = alemat::children![ + Operator::lparens(), + Ident::from("n"), + Operator::eq(), + Num::from(0), + Operator::rparens(), + ]; + + let over = alemat::children![Ident::from("k"), Operator::plus(), Num::from(1)]; + + let out = MathMl::with_content(alemat::children![UnderOver::builder() + .expr(Operator::sum()) + .under(under) + .over(over) + .build()]) + .render(); + + crate::snap_test!(out, name: "underover_many"); +} + #[test] fn underover_integral() { let out = MathMl::with_content(alemat::children![ diff --git a/tests/snapshots/subsup_many.snap b/tests/snapshots/subsup_many.snap new file mode 100644 index 0000000..4ccefbc --- /dev/null +++ b/tests/snapshots/subsup_many.snap @@ -0,0 +1,40 @@ +--- +source: tests/scripted/mod.rs +expression: input +--- + + + + ∫ + + + + ( + + + n + + + = + + + 0 + + + ) + + + + + k + + + + + + + 1 + + + + + diff --git a/tests/snapshots/underover_many.snap b/tests/snapshots/underover_many.snap new file mode 100644 index 0000000..438fdf0 --- /dev/null +++ b/tests/snapshots/underover_many.snap @@ -0,0 +1,40 @@ +--- +source: tests/scripted/mod.rs +expression: input +--- + + + + ∑ + + + + ( + + + n + + + = + + + 0 + + + ) + + + + + k + + + + + + + 1 + + + + +