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
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![doc = include_str!("readme.md")]

mod matrix;

use crate::{blocks::MathStyle, LineThickness, MathFraction, MathML, MathMultiScript, MathRow, MathTable};

pub use self::matrix::*;

/// Build a normal fraction.
///
/// # Input
///
/// ```tex
/// \begin{vmatrix} a & b \\ c & d \end{vmatrix}
/// ```
///
/// # Output
#[doc = include_str!("vmatrix.xml")]
pub fn frac<N, D>(numerator: N, denominator: D) -> MathML
where
    N: Into<MathML>,
    D: Into<MathML>,
{
    MathFraction::new(numerator, denominator).into()
}

/// Renders a matrix with vertical bars.
///
/// # Input
///
/// ```tex
/// \begin{vmatrix} a & b \\ c & d \end{vmatrix}
/// ```
///
/// # Output
#[doc = include_str!("vmatrix.xml")]
// noinspection SpellCheckingInspection
pub fn dfrac<N, D>(numerator: N, denominator: D) -> MathML
where
    N: Into<MathML>,
    D: Into<MathML>,
{
    MathStyle::display(frac(numerator, denominator)).into()
}

/// Renders a matrix with vertical bars.
///
/// # Input
///
/// ```tex
/// \begin{vmatrix} a & b \\ c & d \end{vmatrix}
/// ```
///
/// # Output
#[doc = include_str!("vmatrix.xml")]
// noinspection SpellCheckingInspection
pub fn cfrac(numerator: MathML, denominator: MathML) -> MathML {
    todo!()
}

pub fn binom(numerator: MathML, denominator: MathML) -> MathML {
    MathFraction::new(numerator, denominator).with_thickness(LineThickness::Length(0)).into()
}

/// Renders a matrix with vertical bars.
///
/// # Input
///
/// ```tex
/// \begin{vmatrix} a & b \\ c & d \end{vmatrix}
/// ```
///
/// # Output
#[doc = include_str!("vmatrix.xml")]
// noinspection SpellCheckingInspection
pub fn cbinom(numerator: MathML, denominator: MathML) -> MathML {
    MathMultiScript::sub_super_script(MathML::identifier("C"), numerator, denominator).into()
}

pub fn legendre_symbols(numerator: MathML, denominator: MathML) -> MathML {
    todo!()
}

pub fn isotope(nucleus: usize, atomic_number: usize, mass_number: usize) -> MathML {
    todo!()
}

#[inline(always)]
pub fn safe_html_char<W>(writer: &mut W, c: char) -> std::fmt::Result
where
    W: std::fmt::Write,
{
    match c {
        '<' => writer.write_str("&lt;"),
        '>' => writer.write_str("&gt;"),
        '&' => writer.write_str("&amp;"),
        '"' => writer.write_str("&quot;"),
        '\'' => writer.write_str("&apos;"),
        _ => writer.write_char(c),
    }
}

#[inline(always)]
pub fn safe_html_str<W>(writer: &mut W, s: &str) -> std::fmt::Result
where
    W: std::fmt::Write,
{
    for c in s.chars() {
        safe_html_char(writer, c)?;
    }
    Ok(())
}