show_eqn

show_eqn(
    eqns,
    environment=None,
    sep=None,
    label=None,
    label_command=None,
    col_wrap=None,
    float_format=None,
    cell_formatter=None,
    row_formatter=None,
    debug=None,
    print_label=None,
    katex=None,
    env_arg=None,
    **kwargs,
)

Display mathematical equations as formatted LaTeX amsmath block.

Converts Python dictionaries containing symbolic expressions into rendered LaTeX equations suitable for Jupyter notebooks and Quarto documents. Supports multi-column layouts, custom formatting, labeling, and various LaTeX environments.

Parameters

Name Type Description Default
eqns dict[Any, Any] | list[dict[Any, Any]] | Dataframe Equation data as dict, list of dicts, or Dataframe object. Automatically converted to Dataframe internally. For list of dicts: first dict’s keys become Dataframe keys, subsequent dicts add columns where keys match (None for mismatches). See Dataframe.__init__ for details. required
environment str | dict[str, Any] | None LaTeX environment name or custom definition. Built-in environments include “align”, “equation”, “cases”, “gather”, “split”, “alignat”, “rcases”. Can also be a dict or EnvironmentDefinition object for custom environments. Defaults to config.latex.default_environment. None
sep str | list[str] | None Separator(s) between cells in the amsmath block (e.g. LHS & RHS & ...). Can be string or list of strings for finer customization (separator goes between columns: first separator between columns 1-2, etc). Defaults to environment’s default separator (None uses environment default: “&” for align, “” for equation/gather). None
label str | dict[str, str | Callable] | Callable | None Label(s) for cross-referencing equations. Can be: - str: Single label string (pre-formatted with generate_label) - dict: Mapping symbols to label strings or callables - Callable: Function that generates labels, receives single list: [key] + Dataframe[key] Labels should be pre-formatted using generate_label() before passing to show_eqn. Callable labels receive a single list argument: [key, value1, value2, …]. Omitted in KaTeX mode for notebook compatibility. None
label_command str | None LaTeX label command (e.g., r”“). Defaults to config.latex.default_label_command. None
col_wrap str | dict | list | Dataframe | Callable | None Column wrapping specifications for LaTeX formatting. Can be str, dict, list, Dataframe, or Callable. For lists, the last element automatically fills remaining columns. Supports tuple values for prefix/suffix: [None, (“=”, ““), (r”\quad(“,”)“)] works correctly. List elements: None (no wrapping), str (prefix only), tuple (prefix, suffix), or Callable. Defaults to config.display.col_wrap. None
float_format str | dict | list | Dataframe | None Format specification for float values (does not affect int). Can be str (all floats), list of str (per column), dict (per row), dict of list or Dataframe (per cell). For lists, the last element automatically fills remaining columns. Example: [None, “.3f”, “.2f”] means col 0: no format, col 1: “.3f”, col 2+: “.2f”. Supports format specs with or without braces (e.g., “.3f” or “{:.3f}”). Defaults to config.display.default_float_format. None
cell_formatter Callable | dict | list | Dataframe | None Custom cell value formatter function(s). Can be single Callable[(value, col_index) -> str] (all cells), list of Callable (per column), dict of Callable (per row if key matches), dict of list of Callable or Dataframe (per cell). For lists, the last element automatically fills remaining columns. Defaults to config.display.cell_formatter. None
row_formatter Callable | dict | None Custom row-level formatter function(s). Can be single Callable[(row_latex_str) -> str] or dict mapping symbol keys to formatters. Applies to the composed entire row (str). Defaults to config.display.row_formatter. None
debug bool | None Enable debug mode to print generated LaTeX source code. Defaults to config.display.debug. None
print_label bool | None Print labels to console for easy copy-paste reference. Defaults to config.display.print_label. None
katex bool | None Enable KaTeX compatibility mode (disables label commands). Defaults to config.display.katex. None
env_arg str | None Optional environment argument (e.g., “{2}” for alignat{2}). User provides complete argument string including braces. None
**kwargs Any Additional keyword arguments: - language (str): Document-level language override for translations - substitutions (dict): Custom translation dictionary (highest priority) - Other sympy.latex() parameters (e.g., mul_symbol, fold_frac_powers) {}

Returns

Name Type Description
Latex IPython.display.Latex object containing rendered LaTeX equations

Examples

from keecas import symbols, u, pc, show_eqn

# Basic parameter display with subscripted symbols
F, A_load = symbols(r"F, A_{load}")

_p = {
    F: 100*u.kN,
    A_load: 20*u.cm**2
}

show_eqn(_p)

\[\begin{align} F & = 100{\,}\text{kN} \\[8pt] A_{load} & = 20{\,}\text{cm}^{2} \end{align}\]

# Multi-column with expressions and values
sigma_Sd = symbols(r"\sigma_{Sd}")

_e = {
    sigma_Sd: "F/A_load" | pc.parse_expr
}

_v = {k: v | pc.subs(_p | _e) | pc.convert_to([u.MPa]) | pc.N for k, v in _e.items()}

show_eqn([_p|_e, _v])

\[\begin{align} F & = 100{\,}\text{kN} & \\[8pt] A_{load} & = 20{\,}\text{cm}^{2} & \\[8pt] \sigma_{Sd} & = \dfrac{F}{A_{load}} & = 50.0{\,}\text{MPa} \end{align}\]

# Custom formatting and labels

from keecas import config

config.display.print_label = True

# label dictionary
_l = {
    F: 'force',
    A_load: 'area',
    sigma_Sd: 'stress-calc',
}

# specific float formatting
_f = {
    F: '{:.1f}', # applied to all element in the row
    A_load: '{:.2f}', # applied to all element in the row
    sigma_Sd: [None, None, '.3f'], # per cell formatting
}

show_eqn([_p|_e, _v], float_format=_f, label=_l)
F: force
A_{load}: area
\sigma_{Sd}: stress-calc

\[\begin{align} F & = 100{\,}\text{kN} & \label{force} \\[8pt] A_{load} & = 20{\,}\text{cm}^{2} & \label{area} \\[8pt] \sigma_{Sd} & = \dfrac{F}{A_{load}} & = 50.000{\,}\text{MPa} \label{stress-calc} \end{align}\]

# Custom formatting and description

from keecas import config

config.display.print_label = True

# short description
_d = {
    F: 'applied force',
    A_load: 'area of application',
    sigma_Sd: 'stress',
}

# use hash function to create unique labels
_l = {k: hash(v) for k,v in _d.items()}

show_eqn(
    [_p|_e, _v, _d],
    float_format=['', '.2f', '.4f'],
    # float_format='.2f',
    label=_l
)
F: -8924646459609296223
A_{load}: 5674861360200031250
\sigma_{Sd}: -4637011226190381841

\[\begin{align} F & = 100{\,}\text{kN} & & \quad\text{applied force} \label{-8924646459609296223} \\[8pt] A_{load} & = 20{\,}\text{cm}^{2} & & \quad\text{area of application} \label{5674861360200031250} \\[8pt] \sigma_{Sd} & = \dfrac{F}{A_{load}} & = 50.0000{\,}\text{MPa} & \quad\text{stress} \label{-4637011226190381841} \end{align}\]

# Different environments
from IPython.display import display

# tip: if show_eqn used mid-cell, use display() to emit rendered output to notebook
display(show_eqn(_p, environment="align"))  # aligned at '=' sign
show_eqn(_p, environment="gather")    # Centered, no alignment

\[\begin{align} F & = 100{\,}\text{kN} \\[8pt] A_{load} & = 20{\,}\text{cm}^{2} \end{align}\]

\[\begin{gather} F = 100{\,}\text{kN} \\[8pt] A_{load} = 20{\,}\text{cm}^{2} \end{gather}\]

# Custom environment with parentheses
custom_env = {
    "separator": "&",
    "line_separator": r" \\ ",
    "supports_multiple_labels": True,
    "outer_environment": "align",
    "inner_environment": "aligned",
    "inner_prefix": r"\left(",
    "inner_suffix": r"\right)",
}
show_eqn([_e, _v], environment=custom_env)

\[\begin{align} \left(\begin{aligned} \sigma_{Sd} & = \dfrac{F}{A_{load}} & = 50.0{\,}\text{MPa} \end{aligned}\right) \end{align}\]

# Custom environment for one-line display
one_line_env = {
    "separator": " ",
    "line_separator": r";\quad ",
    "supports_multiple_labels": False,
    "outer_environment": "equation",
}
show_eqn([_p|_e, _v], environment=one_line_env)

\[\begin{equation} F = 100{\,}\text{kN} ;\quad A_{load} = 20{\,}\text{cm}^{2} ;\quad \sigma_{Sd} = \dfrac{F}{A_{load}} = 50.0{\,}\text{MPa} \end{equation}\]

See Also

Notes

  • LaTeX output respects config.katex setting (disables labels for KaTeX compatibility)
  • Float formatting supports format specs with or without braces: “.3f” or “{:.3f}”
  • Environment separator defaults to None (uses environment-specific default)
  • Labels use config.latex.eq_prefix and eq_suffix for consistent referencing
  • use config.display.print_label=True to display resulting label to be used for referencing (it will display the label even in KaTeX mode)