Skip to main content

latex_roundtrip/
latex_roundtrip.rs

1//! Demonstrates the LaTeX renderer (round-trip serialisation).
2//!
3//! Run with: cargo run --example latex_roundtrip
4
5use term_maths::{render, to_latex};
6
7fn main() {
8    let examples = [
9        r"\frac{a}{b}",
10        r"x^2 + y^2 = z^2",
11        r"\sum_{i=1}^{n} x_i",
12        r"\sqrt{b^2 - 4ac}",
13        r"\begin{pmatrix} a & b \\ c & d \end{pmatrix}",
14        r"\mathbb{R}^n",
15    ];
16
17    for latex in &examples {
18        println!("Original:    {}", latex);
19        let roundtrip = to_latex(latex);
20        println!("Round-trip:  {}", roundtrip.trim());
21        println!("Rendered:");
22        println!("{}", render(latex));
23        println!();
24    }
25}