format_value

format_value(value, col_index=0, **kwargs)

Format a value to LaTeX string using type-based dispatch.

This is the main entry point for formatting values in keecas equations. Dispatches to specialized formatters based on value type. For unhandled types, falls back to sympy.latex().

Parameters

value : Any Value to format (any type) col_index : int, optional Column index - 0 for LHS, 1+ for RHS (default: 0) Kept for API consistency but not used by default formatters **kwargs Additional arguments passed to latex() function (e.g., mul_symbol, mode, fold_frac_powers)

Returns

str LaTeX string representation

Examples

from keecas import format_value, symbols

# Define symbol with subscript
sigma_Rd = symbols(r"\sigma_{Rd}")

# Format symbol (LHS)
format_value(sigma_Rd)  # Returns: '\sigma_{Rd}'
'\\sigma_{Rd}'
# Format integer (pure conversion)
format_value(42, col_index=1)  # Returns: '42'
'42'
# Format string
format_value("text", col_index=0)  # Returns: '\text{text}'
'\\text{text}'

Notes

To register custom type formatters:

# Define your custom type first
class MyType:
    pass

# Then register a formatter for it
@format_value.register(MyType)
def format_mytype(value, col_index=0, **kwargs):
    return r"\text{My custom format}"

Supported types (built-in registrations): - str: Plain text wrapped in - int: Integer to LaTeX string - float: Float to LaTeX string - IPython.display.Markdown: Wrapped in - pint.Quantity: Converted to SymPy, then formatted - sympy.Mul: Numeric/unit separation, then formatted as Basic - sympy.Basic: LaTeX via sympy.latex()

See Also

format_str : String formatter format_int : Integer formatter format_float : Float formatter format_sympy : SymPy expression formatter