1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use super::*;

impl MathOperator {
    pub fn new<S>(text: S) -> Self
    where
        S: ToString,
    {
        Self { operator: text.to_string() }
    }
}

impl MathSqrt {
    pub fn new(base: MathML) -> Self {
        Self { base, surd: None }
    }
    pub fn surd(base: MathML, power: MathML) -> Self {
        Self { base, surd: Some(power) }
    }
}

impl MathMultiScript {
    pub fn new(base: MathML, ru: Vec<MathML>, rd: Vec<MathML>, lu: Vec<MathML>, ld: Vec<MathML>) -> Self {
        Self { base, ru, rd, lu, ld, attributes: BTreeMap::new() }
    }
    pub fn sub_script(base: MathML, sub: MathML) -> Self {
        Self { base, ru: Vec::new(), rd: Vec::new(), lu: Vec::new(), ld: vec![sub], attributes: BTreeMap::new() }
    }
    pub fn is_sub_script(&self) -> bool {
        self.ru.is_empty() && self.rd.is_empty() && self.lu.is_empty() && self.ld.len() == 1
    }
    pub fn super_script(base: MathML, sup: MathML) -> Self {
        Self { base, ru: Vec::new(), rd: Vec::new(), lu: vec![sup], ld: Vec::new(), attributes: BTreeMap::new() }
    }
    pub fn is_super_script(&self) -> bool {
        self.ru.is_empty() && self.rd.is_empty() && self.lu.len() == 1 && self.ld.is_empty()
    }
    pub fn sub_super_script(base: MathML, sub: MathML, sup: MathML) -> Self {
        Self { base, ru: Vec::new(), rd: Vec::new(), lu: vec![sup], ld: vec![sub], attributes: BTreeMap::new() }
    }
    pub fn is_sub_super_script(&self) -> bool {
        self.ru.is_empty() && self.rd.is_empty() && self.lu.len() == 1 && self.ld.len() == 1
    }
}

impl MathFenced {
    pub fn new<S>(base: MathML, lhs: S, rhs: S) -> Self
    where
        S: Into<String>,
    {
        Self { base, lhs: lhs.into(), rhs: rhs.into() }
    }
}

impl MathUnderOver {
    pub fn under(base: MathML, under: MathML) -> Self {
        Self { base, under: Some(under), over: None, attributes: BTreeMap::new() }
    }
    pub fn over(base: MathML, over: MathML) -> Self {
        Self { base, under: None, over: Some(over), attributes: BTreeMap::new() }
    }
    pub fn under_over(base: MathML, under: MathML, over: MathML) -> Self {
        Self { base, under: Some(under), over: Some(over), attributes: BTreeMap::new() }
    }
    pub fn with_accent_over(mut self, accent: bool) -> Self {
        if accent {
            self.attributes.insert("accent".to_string(), "true".to_string());
        }
        else {
            self.attributes.remove("accent");
        }
        self
    }
    pub fn with_accent_under(mut self, accent: bool) -> Self {
        if accent {
            self.attributes.insert("accentunder".to_string(), "true".to_string());
        }
        else {
            self.attributes.remove("accentunder");
        }
        self
    }
}
impl MathML {
    pub fn operation<S>(text: S) -> Self
    where
        S: ToString,
    {
        MathOperator::new(text).into()
    }
}