formatters.format_mul
format_mul(value, col_index=0, **kwargs)Format Mul expressions with numeric/unit separation for simple cases.
For simple multiplication of numeric values and units (e.g., 5*meter), applies transformation to separate numeric and unit parts for cleaner LaTeX display. Complex calculations are formatted as-is.
Transformation applies only when ALL conditions are met: - No free symbols (variables like x, y, sigma) - No division operations (no Pow with negative exponent) - No addition/subtraction (no Add terms) - Single unit quantity (multiple units indicate compound units from calculation)
Examples:
Simple cases (transformed): - 5meter -> “5 ” - 3.14kilogram -> “3.14 ”
Complex cases (NOT transformed, formatted as-is): - 5kN / (3m) -> displayed as division expression - 15kNm -> displayed as-is (compound units from torque calculation) - x * y -> displayed as symbolic multiplication - (a + b) * meter -> displayed with addition
Parameters
value : Mul Multiplication expression to format col_index : int, optional Column index (0 = LHS, 1+ = RHS) **kwargs Passed to format_sympy()
Returns
str LaTeX string representation
Notes
Transformation: 5meter -> UnevaluatedExpr(5) UnevaluatedExpr(meter) This produces “5 ” instead of “5meter” in LaTeX.
For complex expressions with calculations, the function preserves the original structure to maintain clarity in mathematical notation.