//! OMML read into the tree and written as LaTeX means what GridCraft's direct OMML-to-LaTeX //! reader (`crates/xlsx/src/omml.rs`) gave for its test cases, so GridCraft can read equations in //! drawings through this crate. The LaTeX is compared by what it reads back as, not byte for byte. use craft_math::{math, math_latex, omml}; fn tex(inner: &str) -> String { let x = format!(r#"{inner}"#); math_latex::to_latex(&omml::read_str(&x).unwrap().nodes) } #[test] fn gridcraft_omml_cases_mean_the_same_latex() { let brace = |chr: &str, pos: &str| { format!( "x" ) }; let lim = "n"; let under = format!("{}{lim}", brace("\u{23DF}", "bot")); let cases: Vec<(String, &str)> = vec![ ("x+1".into(), "x+1"), ("ab".into(), "\\frac{a}{b}"), ("x2".into(), "{x}^{2}"), ("π".into(), "\\sqrt{\\pi }"), ("i=1ni".into(), "\\sum_{i=1}^{n} {i}"), ("f".into(), "\\int {f}"), ("1001".into(), "\\left[ \\begin{matrix}1 & 0 \\\\ 0 & 1\\end{matrix} \\right]"), ("sinx".into(), "\\sin x"), ("R".into(), "\\mathbb{R}"), ("if {x}".into(), "\\text{if \\{x\\}}"), ("x".into(), "\\hat{x}"), (under.clone(), "\\underbrace{x}_{n}"), (format!("{under}2"), "{\\underbrace{x}_{n}}^{2}"), (format!("{}{lim}", brace("\u{23DE}", "top")), "\\overbrace{x}^{n}"), (format!("a{lim}"), "\\underset{n}{a}"), (format!("{}+1{lim}", brace("\u{23DF}", "bot")), "\\underset{n}{\\underbrace{x}+1}"), ]; for (x, want) in cases { let got = tex(&x); assert_eq!(math::to_linear(&math_latex::parse_latex(&got)), math::to_linear(&math_latex::parse_latex(want)), "{x}: {got} for {want}"); } }