mathml_latex/codegen/
as_text.rs1use super::*;
2use crate::LaTeXBlock;
3
4impl<'i> LaTeXNode<'i> {
5 pub fn as_identifier(&self) -> &'i str {
6 match self {
7 LaTeXNode::Letter { identifier } => identifier,
8 LaTeXNode::Operation { operator } => operator,
9 _ => "",
10 }
11 }
12}
13
14impl<'i> Display for LaTeXNode<'i> {
15 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
16 match self {
17 LaTeXNode::ArticleRoot { .. } => {
18 todo!()
19 }
20 LaTeXNode::ArticleText { .. } => {
21 todo!()
22 }
23 LaTeXNode::MathRoot { .. } => {
24 todo!()
25 }
26 LaTeXNode::Row { children } => {
27 for child in children {
28 write!(f, "{}", child)?;
29 }
30 Ok(())
31 }
32 LaTeXNode::Block(v) => Display::fmt(v, f),
33 LaTeXNode::Command { .. } => {
34 todo!()
35 }
36 LaTeXNode::MathText { .. } => {
37 todo!()
38 }
39 LaTeXNode::Number { number } => f.write_str(number),
40 LaTeXNode::Operation { .. } => {
41 todo!()
42 }
43 LaTeXNode::Superscript { .. } => {
44 todo!()
45 }
46 LaTeXNode::Letter { .. } => {
47 todo!()
48 }
49 LaTeXNode::NewLine => f.write_str("\\\\"),
50 LaTeXNode::Ampersand => f.write_str("&"),
51 }
52 }
53}
54
55impl<'i> Display for LaTeXBlock<'i> {
56 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
57 writeln!(f, "\\begin{{{}}}", self.kind)?;
58 for child in &self.children {
59 write!(f, "{}", child)?;
60 }
61 writeln!(f, "\\end{{{}}}", self.kind)
62 }
63}