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
use std::fmt::{Display, Formatter};
mod display;
use crate::MathML;

/// math identifier, `<mi>`
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MathIdentifier {
    identifier: String,
    variant: MathVariant,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MathText {
    is_string: bool,
    text: String,
}

/// mi mathvariant attribute
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MathVariant {
    Normal,
    Italic,
    Bold,
    BoldItalic,
    DoubleStruck,
    BoldFraktur,
    Script,
    BoldScript,
    Fraktur,
    SansSerif,
    BoldSansSerif,
    SansSerifItalic,
    SansSerifBoldItalic,
    Monospace,
}

impl MathIdentifier {
    pub fn new<S>(text: S, variant: MathVariant) -> Self
    where
        S: ToString,
    {
        Self { identifier: text.to_string(), variant }
    }
    pub fn normal<S>(text: S) -> Self
    where
        S: ToString,
    {
        Self { identifier: text.to_string(), variant: MathVariant::Normal }
    }
    pub fn italic<S>(text: S) -> Self
    where
        S: ToString,
    {
        Self { identifier: text.to_string(), variant: MathVariant::Italic }
    }
    pub fn get_variant(&self) -> MathVariant {
        self.variant
    }
    pub fn get_identifier(&self) -> &str {
        &self.identifier
    }
}

impl MathML {
    pub fn identifier<S>(text: S) -> Self
    where
        S: ToString,
    {
        MathIdentifier::italic(text).into()
    }
}

impl MathText {
    pub fn text<S>(text: S) -> Self
    where
        S: ToString,
    {
        Self { text: text.to_string(), is_string: false }
    }
    pub fn string<S>(text: S) -> Self
    where
        S: ToString,
    {
        Self { text: text.to_string(), is_string: true }
    }
}