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

impl<'i> LaTeXNode<'i> {
    pub fn as_identifier(&self) -> &'i str {
        match self {
            LaTeXNode::Letter { identifier } => identifier,
            LaTeXNode::Operation { operator } => operator,
            _ => "",
        }
    }
}

impl<'i> Display for LaTeXNode<'i> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            LaTeXNode::ArticleRoot { .. } => {
                todo!()
            }
            LaTeXNode::ArticleText { .. } => {
                todo!()
            }
            LaTeXNode::MathRoot { .. } => {
                todo!()
            }
            LaTeXNode::Row { children } => {
                for child in children {
                    write!(f, "{}", child)?;
                }
                Ok(())
            }
            LaTeXNode::Block(v) => Display::fmt(v, f),
            LaTeXNode::Command { .. } => {
                todo!()
            }
            LaTeXNode::MathText { .. } => {
                todo!()
            }
            LaTeXNode::Number { number } => f.write_str(number),
            LaTeXNode::Operation { .. } => {
                todo!()
            }
            LaTeXNode::Superscript { .. } => {
                todo!()
            }
            LaTeXNode::Letter { .. } => {
                todo!()
            }
            LaTeXNode::NewLine => f.write_str("\\\\"),
            LaTeXNode::Ampersand => f.write_str("&"),
        }
    }
}

impl<'i> Display for LaTeXBlock<'i> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "\\begin{{{}}}", self.kind)?;
        for child in &self.children {
            write!(f, "{}", child)?;
        }
        writeln!(f, "\\end{{{}}}", self.kind)
    }
}