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
use super::*;
use crate::MathSpace;

impl Display for MathRoot {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "<math")?;
        for (key, value) in &self.attributes {
            write!(f, " {}=\"{}\"", key, value)?;
        }
        write!(f, ">")?;
        for child in &self.children {
            write!(f, "{}", child)?;
        }
        write!(f, "</math>")
    }
}

impl Display for MathPhantom {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "<mphantom>")?;
        write!(f, "{}", self.inner)?;
        write!(f, "</mphantom>")
    }
}
impl Display for MathStyle {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "<mstyle")?;
        for (key, value) in &self.attributes {
            write!(f, " {}=\"{}\"", key, value)?;
        }
        write!(f, ">")?;
        write!(f, "{}", self.base)?;
        write!(f, "</mstyle>")
    }
}
impl Display for MathRow {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str("<mrow>")?;
        for child in &self.children {
            write!(f, "{}", child)?;
        }
        f.write_str("</mrow>")
    }
}

impl Display for MathFunction {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        let identifier = MathIdentifier::normal(&self.name);
        if self.body.is_empty() {
            write!(f, "{}", identifier)
        }
        else {
            let mut row = MathRow::new(vec![identifier.into(), MathSpace::new(0.167).into()]);
            row.mut_items().extend(self.body.iter().cloned());
            write!(f, "{}", row)
        }
    }
}