Skip to main content

LaTeXFormatter

Trait LaTeXFormatter 

Source
pub trait LaTeXFormatter {
    // Required methods
    fn to_latex_with_depth(
        &self,
        context: &LaTeXContext,
        depth: usize,
    ) -> Result<String, FormattingError>;
    fn function_to_latex_with_depth(
        &self,
        name: &str,
        args: &[Expression],
        context: &LaTeXContext,
        depth: usize,
    ) -> Result<String, FormattingError>;

    // Provided methods
    fn to_latex<C>(&self, context: C) -> Result<String, FormattingError>
       where C: Into<Option<LaTeXContext>> { ... }
    fn function_to_latex(
        &self,
        name: &str,
        args: &[Expression],
        context: &LaTeXContext,
    ) -> Result<String, FormattingError> { ... }
}
Expand description

Format the expression to LaTeX

Required Methods§

Source

fn to_latex_with_depth( &self, context: &LaTeXContext, depth: usize, ) -> Result<String, FormattingError>

Format with explicit recursion depth tracking

Internal method that provides stack overflow protection by tracking recursion depth. This method returns a Result to allow proper error propagation during recursive formatting.

§Arguments
  • context - LaTeX formatting configuration
  • depth - Current recursion depth (starts at 0)
§Returns
  • Ok(String) - Successfully formatted LaTeX expression
  • Err(String) - Error message if limits exceeded
§Safety Limits
  • Maximum recursion depth: 1000 levels
  • Maximum terms per operation: 10000 terms/factors/arguments
Source

fn function_to_latex_with_depth( &self, name: &str, args: &[Expression], context: &LaTeXContext, depth: usize, ) -> Result<String, FormattingError>

Convert function to LaTeX with context and depth tracking

Provided Methods§

Source

fn to_latex<C>(&self, context: C) -> Result<String, FormattingError>

Format an Expression as LaTeX mathematical notation

Converts mathematical expressions into LaTeX format suitable for rendering in mathematical documents and publications.

§Arguments
  • context - LaTeX formatting configuration
§Context Options
  • needs_parentheses - Whether to wrap the entire expression in parentheses
§Examples
use mathhook_core::{Expression, expr};
use mathhook_core::formatter::latex::{LaTeXFormatter, LaTeXContext};

let expression = expr!(x ^ 2);
let context = LaTeXContext::default();
let result = expression.to_latex(context).unwrap();
assert!(result.contains("x"));
assert!(result.contains("2"));
§Error Handling

Returns error messages for expressions that exceed safety limits:

  • Maximum recursion depth (1000 levels)
  • Maximum terms per operation (10000 terms)
Source

fn function_to_latex( &self, name: &str, args: &[Expression], context: &LaTeXContext, ) -> Result<String, FormattingError>

Convert function to LaTeX (convenience method)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§