muutils.nbutils.print_tex
quickly print a sympy expression in latex
1"""quickly print a sympy expression in latex""" 2 3from __future__ import annotations 4 5import sympy as sp # type: ignore # pyright: ignore[reportMissingTypeStubs] 6from IPython.display import Math, display # type: ignore # pyright: ignore[reportUnknownVariableType] 7 8 9def print_tex( 10 expr: sp.Expr, # type: ignore 11 name: str | None = None, 12 plain: bool = False, 13 rendered: bool = True, 14): 15 """function for easily rendering a sympy expression in latex""" 16 out: str = sp.latex(expr) # pyright: ignore[reportUnknownVariableType] 17 if name is not None: 18 out = f"{name} = {out}" 19 20 if plain: 21 print(out) # pyright: ignore[reportUnknownArgumentType] 22 if rendered: 23 display(Math(out)) # pyright: ignore[reportUnusedCallResult]
def
print_tex( expr: sympy.core.expr.Expr, name: str | None = None, plain: bool = False, rendered: bool = True):
10def print_tex( 11 expr: sp.Expr, # type: ignore 12 name: str | None = None, 13 plain: bool = False, 14 rendered: bool = True, 15): 16 """function for easily rendering a sympy expression in latex""" 17 out: str = sp.latex(expr) # pyright: ignore[reportUnknownVariableType] 18 if name is not None: 19 out = f"{name} = {out}" 20 21 if plain: 22 print(out) # pyright: ignore[reportUnknownArgumentType] 23 if rendered: 24 display(Math(out)) # pyright: ignore[reportUnusedCallResult]
function for easily rendering a sympy expression in latex