opensrdk_symbolic_computation/expression/matrix_expression/
tex_code.rs1use std::collections::HashMap;
2
3use crate::{BracketsLevel, MatrixExpression};
4
5impl MatrixExpression {
6 pub(crate) fn _tex_code(
7 &self,
8 variables: &HashMap<&str, &str>,
9 _brackets_level: BracketsLevel,
10 ) -> String {
11 match self {
12 MatrixExpression::T(v) => MatrixExpression::tex_code_t(v, variables),
13 MatrixExpression::Inv(v) => MatrixExpression::tex_code_inv(v, variables),
14 MatrixExpression::Det(v) => MatrixExpression::tex_code_det(v, variables),
15 }
16 }
17
18 pub fn tex_code(&self, symbols: &HashMap<&str, &str>) -> String {
19 self._tex_code(symbols, BracketsLevel::None)
20 }
21}
22
23#[cfg(test)]
24mod tests {
25 use std::collections::{HashMap, HashSet};
26
27 use opensrdk_linear_algebra::{sparse::SparseTensor, Matrix};
28
29 use crate::{new_variable, new_variable_tensor, Expression, MatrixExpression, Size};
30
31 #[test]
32 fn it_works() {
33 let id = "x";
34 let ea = new_variable_tensor((id).to_string(), vec![Size::Many, Size::Many]);
35 let tex_symbols = vec![("x", "y")].into_iter().collect();
36
37 let ea_t = ea.clone().t();
38 let tex_a_t = ea_t.tex_code(&tex_symbols);
39 assert_eq!("{y}^\\top", tex_a_t);
40
41 let ea_inv = ea.clone().inv();
42 let tex_a_inv = ea_inv.tex_code(&tex_symbols);
43 assert_eq!("{{y}^{-1}}", tex_a_inv);
44
45 let ea_det = ea.clone().det();
46 let tex_a_det = ea_det.tex_code(&tex_symbols);
47 assert_eq!("\\left\\|{y}\\right\\|", tex_a_det);
48 }
49}