1"""quickly print a sympy expression in latex"""

2

3 import sympy as sp # type: ignore

4 from IPython.display import Math, display # type: ignore

5

6

7 def print_tex(

8 expr: sp.Expr,

9 name: str | None = None,

10 plain: bool = False,

11 rendered: bool = True,

12):

13 """function for easily rendering a sympy expression in latex"""

14 out: str = sp.latex(expr)

15 if name is not None:

16 out = f"{name} = {out}"

17

18 if plain:

19 print(out)

20 if rendered:

21 display(Math(out))