Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use LaTeX symbols in sympy expressions

I would like to do some calculations and then have those plotted using sympy. I want to use consistent notation, so I need to define a symbol which will be printed as $\Delta_l^y$.

What I have tried so far:

delta__i_0 = sympy.symbols('Delta__i_0')
sympy.pprint(delta__i_0)

which works fine. Unfortunately

delta__y_l = sympy.symbols('Delta__y_l')
sympy.pprint(delta__y_l)

does not really look nice. Any ideas?

like image 810
laolux Avatar asked Jun 08 '17 18:06

laolux


1 Answers

From the command line Python interpreter, you could use sympy.printing.latex. For example,

import sympy as sym
import sympy.printing as printing
delta__y_l = sym.symbols('Delta__y_l')
print(printing.latex(delta__y_l))

prints

\Delta^{y}_{l}

Or, using IPython notebook, call sym.init_printing() to enable pretty-printing: enter image description here

like image 197
unutbu Avatar answered Nov 14 '22 13:11

unutbu