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
use super::*;
impl Debug for BashicuMatrixSystem {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut result = String::new();
for c in &self.matrix {
result.push('(');
for (i, &r) in c.iter().enumerate() {
result.push_str(&r.to_string());
if i != c.len() - 1 {
result.push(',');
}
}
result.push(')');
}
result.push_str(&format!("[{}]", self.expand));
write!(f, "{}", result)
}
}
impl Display for BashicuMatrixSystem {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut result = String::new();
for c in &self.matrix {
result.push('(');
for (i, &r) in c.iter().enumerate() {
result.push_str(&r.to_string());
if i != c.len() - 1 {
result.push(',');
}
}
result.push(')');
}
write!(f, "{}", result)
}
}
impl Latexify for BashicuMatrixSystem {
type Context = BMSConfig;
fn fmt<W: Write>(&self, c: &Self::Context, f: &mut W) -> std::fmt::Result {
if c.display {
f.write_str("\\begin{bmatrix}\n")?;
for i in 0..self.ys() {
for j in 0..self.xs() {
if c.color {
// if self.get_bad_root() == Some(i) {
// f.write_str("\\color{red}")?;
// }
// else if self.get_lowermost_nonzero(&self.matrix[j]) == Some(i) {
// f.write_str("\\color{blue}")?;
// }
}
Latexify::fmt(&self.matrix[j][i], &(), f)?;
if j != self.xs() - 1 {
f.write_str(" & ")?;
}
else if c.ellipsis {
f.write_str(" & \\cdots")?;
}
}
f.write_str("\\\\\n")?;
}
f.write_str("\\end{bmatrix}")?;
}
else {
for coloum in &self.matrix {
f.write_char('(')?;
for (i, &r) in coloum.iter().enumerate() {
if i != 0 {
f.write_str(",")?;
}
Latexify::fmt(&r, &(), f)?;
}
f.write_str(")")?
}
if c.ellipsis {
f.write_str("(\\cdots)")?
}
}
Ok(())
}
}
impl BMSConfig {
/// Get the number of rows in the matrix
pub fn render(&self, bms: &BashicuMatrixSystem) -> String {
bms.to_latex(self)
}
}
impl BashicuMatrixSystem {
fn max_width(&self) -> usize {
self.matrix.iter().map(|c| c.len()).max().unwrap_or(0)
}
}