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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
use super::*;

impl Default for MathRoot {
    fn default() -> Self {
        Self { children: Vec::new(), attributes: BTreeMap::new() }
    }
}

impl MathElement for MathRoot {
    fn tag_name(&self) -> &'static str {
        "math"
    }

    fn get_attributes(&self) -> &BTreeMap<String, String> {
        &self.attributes
    }

    fn mut_attributes(&mut self) -> &mut BTreeMap<String, String> {
        &mut self.attributes
    }
}

impl MathRoot {
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn new<I>(children: I) -> Self
    where
        I: IntoIterator<Item = MathML>,
    {
        Self { children: children.into_iter().collect(), ..Default::default() }
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn with_display_style(self, display: bool) -> Self {
        let display = if display { "block" } else { "inline" };
        self.with_attribute("display", display)
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn with_namespace(self) -> Self {
        self.with_attribute("xmlns", "http://www.w3.org/1998/Math/MathML")
    }
}

impl MathRow {
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn new<I>(items: I) -> Self
    where
        I: IntoIterator<Item = MathML>,
    {
        Self { children: items.into_iter().collect(), grouped: false }
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn group<I>(items: I) -> Self
    where
        I: IntoIterator<Item = MathML>,
    {
        Self { children: items.into_iter().collect(), grouped: true }
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn get_items(&self) -> &[MathML] {
        &self.children
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn mut_items(&mut self) -> &mut Vec<MathML> {
        &mut self.children
    }
}

impl MathElement for MathStyle {
    fn tag_name(&self) -> &'static str {
        "mstyle"
    }

    fn get_attributes(&self) -> &BTreeMap<String, String> {
        &self.attributes
    }

    fn mut_attributes(&mut self) -> &mut BTreeMap<String, String> {
        &mut self.attributes
    }
}

impl MathStyle {
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn display<M>(base: M) -> Self
    where
        M: Into<MathML>,
    {
        Self { base: base.into(), attributes: Default::default() }.with_attribute("displaystyle", "true")
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn inline<M>(base: M) -> Self
    where
        M: Into<MathML>,
    {
        Self { base: base.into(), attributes: Default::default() }.with_attribute("displaystyle", "false")
    }
}
impl MathPhantom {
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn new(inner: MathML) -> Self {
        Self { inner }
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn get_inner(&self) -> &MathML {
        &self.inner
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn mut_inner(&mut self) -> &mut MathML {
        &mut self.inner
    }
}

impl MathFunction {
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn new<S, I>(name: S, body: I) -> Self
    where
        S: ToString,
        I: IntoIterator<Item = MathML>,
    {
        Self { name: name.to_string(), body: body.into_iter().collect() }
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn add_argument(&mut self, argument: MathML) {
        self.body.push(argument);
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn get_arguments(&self) -> &[MathML] {
        &self.body
    }
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn mut_arguments(&mut self) -> &mut Vec<MathML> {
        &mut self.body
    }
}

impl MathElement for MathTable {
    fn tag_name(&self) -> &'static str {
        "mtable"
    }

    fn get_attributes(&self) -> &BTreeMap<String, String> {
        &self.attributes
    }

    fn mut_attributes(&mut self) -> &mut BTreeMap<String, String> {
        &mut self.attributes
    }
}

impl MathTable {
    /// Create a simple math space without any attributes, the unit is `rem`.
    pub fn matrix<I>(stream: I) -> Self
    where
        I: IntoIterator<Item = MathML>,
    {
        Self { stream: stream.into_iter().collect(), attributes: BTreeMap::new() }
    }
}