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 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 ” - -5kN -> “-5 ” (sign kept outside, no parens) - 2.0kN/m^2 -> “2.0 ” (compound unit, one Quantity)
Complex cases (NOT transformed, formatted as-is): - 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 uses as_coeff_Mul() to extract the numeric coefficient, then wraps coefficient and unit separately in UnevaluatedExpr to produce clean LaTeX spacing: “5 ” instead of “5meter”.
Negative coefficients have their sign extracted before wrapping to avoid parenthesization: UnevaluatedExpr(-5) would produce “(-5)” in LaTeX, so the sign is stripped and prepended as a literal “-” after formatting.
For non-numeric leading factors (e.g., pi*meter), falls back to as_two_terms().
For complex expressions with calculations, the function preserves the original structure to maintain clarity in mathematical notation.