mathml_core/helpers/matrix/
mod.rs

1use super::*;
2
3/// Renders a matrix without vertical bars.
4///
5/// # Input
6///
7/// ```tex
8/// \begin{matrix} a & b \\ c & d \end{matrix}
9/// ```
10///
11/// # Output
12#[doc = include_str!("vmatrix.xml")]
13pub fn matrix<I>(rows: I) -> MathML
14where
15    I: IntoIterator<Item = MathML>,
16{
17    MathTable::matrix(rows).into()
18}
19
20/// Renders a small matrix without vertical bars.
21///
22/// # Input
23///
24/// ```tex
25/// \begin{vmatrix} a & b \\ c & d \end{vmatrix}
26/// ```
27///
28/// # Output
29#[doc = include_str!("vmatrix.xml")]
30pub fn smallmatrix<I>(rows: I) -> MathML
31where
32    I: IntoIterator<Item = MathML>,
33{
34    // mstyle scriptlevel="1"
35    todo!()
36}
37
38/// Renders a matrix with brackets.
39///
40/// # Input
41///
42/// ```tex
43/// \begin{bmatrix} a & b \\ c & d \end{bmatrix}
44/// ```
45///
46/// # Output
47#[doc = include_str!("bmatrix.xml")]
48pub fn bmatrix<I>(rows: I) -> MathML
49where
50    I: IntoIterator<Item = MathML>,
51{
52    MathRow::new(vec![MathML::operation("[").into(), MathTable::matrix(rows).into(), MathML::operation("]").into()]).into()
53}
54
55/// Renders a matrix with curly brackets.
56///
57/// # Input
58///
59/// ```tex
60/// \begin{Bmatrix} a & b \\ c & d \end{Bmatrix}
61/// ```
62///
63/// # Output
64#[doc = include_str!("bmatrix2.xml")]
65pub fn Bmatrix<I>(rows: I) -> MathML
66where
67    I: IntoIterator<Item = MathML>,
68{
69    MathRow::new(vec![MathML::operation("{").into(), MathTable::matrix(rows).into(), MathML::operation("}").into()]).into()
70}
71
72/// Renders a matrix with vertical bars.
73///
74/// # Input
75///
76/// ```tex
77/// \begin{vmatrix} a & b \\ c & d \end{vmatrix}
78/// ```
79///
80/// # Output
81#[doc = include_str!("vmatrix.xml")]
82pub fn vmatrix<I>(rows: I) -> MathML
83where
84    I: IntoIterator<Item = MathML>,
85{
86    MathRow::new(vec![MathML::operation("|").into(), MathTable::matrix(rows).into(), MathML::operation("|").into()]).into()
87}
88
89/// Renders a matrix with double vertical bars.
90///
91///
92/// # Input
93///
94/// ```tex
95/// \begin{Vmatrix} a & b \\ c & d \end{Vmatrix}
96/// ```
97///
98/// # Output
99#[doc = include_str!("vmatrix2.xml")]
100pub fn Vmatrix<I>(items: I) -> MathML
101where
102    I: IntoIterator<Item = MathML>,
103{
104    MathRow::new(vec![MathML::operation("‖").into(), MathTable::matrix(items).into(), MathML::operation("‖").into()]).into()
105}
106
107/// Renders a matrix with parentheses.
108///
109/// # Input
110///
111/// ```tex
112/// \begin{pmatrix} a & b \\ c & d \end{pmatrix}
113/// ```
114///
115/// # Output
116#[doc = include_str!("pmatrix.xml")]
117pub fn pmatrix<I>(items: I) -> MathML
118where
119    I: IntoIterator<Item = MathML>,
120{
121    MathRow::new(vec![MathML::operation("(").into(), MathTable::matrix(items).into(), MathML::operation(")").into()]).into()
122}
123
124/// Renders a piecewise function.
125///
126/// # Input
127///
128/// ```tex
129/// \begin{vmatrix} a & b \\ c & d \end{vmatrix}
130/// ```
131///
132/// # Output
133#[doc = include_str!("cases.xml")]
134pub fn cases<I>(items: I) -> MathML
135where
136    I: IntoIterator<Item = MathML>,
137{
138    MathRow::new(vec![MathML::operation("{").into(), MathTable::matrix(items).with_attribute("columnalign", "left").into()])
139        .into()
140}