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
//! # LaTeX Conversion for AST
//!
//! This module provides the `ToLatex` trait for converting AST types back to LaTeX notation.
//!
//! ## Design Philosophy
//!
//! - **Standard LaTeX**: Generate valid LaTeX mathematical notation
//! - **Readability**: Produce clean, readable LaTeX code
//! - **Round-trip Capable**: Output can be parsed back (though not guaranteed identical AST)
//!
//! ## LaTeX Mappings
//!
//! - Integers/Floats: Direct string representation
//! - Rational: `\frac{numerator}{denominator}`
//! - Binary Division: `\frac{left}{right}`
//! - Functions: `\sin`, `\cos`, etc. for known functions, `\operatorname{name}` for others
//! - Square Root: `\sqrt{x}` or `\sqrt[n]{x}`
//! - Derivatives: `\frac{d}{dx}` or `\frac{d^n}{dx^n}`
//! - Partial Derivatives: `\frac{\partial}{\partial x}`
//! - Integrals: `\int_{lower}^{upper} expr dx`
//! - Limits: `\lim_{x \to value^{direction}}`
//! - Sum/Product: `\sum_{i=lower}^{upper}`, `\prod_{i=lower}^{upper}`
//! - Vectors/Matrices: `\begin{pmatrix}...\end{pmatrix}`
//!
//! ## Examples
//!
//! ```
//! use mathlex::ast::{Expression, ExprKind};
//! use mathlex::latex::ToLatex;
//!
//! // 1/2 → "\frac{1}{2}"
//! let expr: Expression = ExprKind::Rational {
//! numerator: Box::new(Expression::integer(1)),
//! denominator: Box::new(Expression::integer(2)),
//! }.into();
//! assert_eq!(expr.to_latex(), r"\frac{1}{2}");
//! ```
pub use ToLatex;