10

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?

laolux
  • 1,445
  • 1
  • 17
  • 28

1 Answers1

13

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

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • Hmm... does not work for me. The LaTeX output works, but unfortunately not the ipython method. It shows '{Deltasymbol}_l__y'. Using python 3.5.3, ipython 5.1.0, sympy 1.0. – laolux Jun 09 '17 at 08:06
  • Wow, now consider that: Your method works in my jupyter notebook, but not in my ipython started from terminal... I guess I should report this as a bug somewhere. Thanks a lot! – laolux Jun 09 '17 at 08:14
  • Directly pprint works for a symbol. But as part of an expression, it is still displayed incorrectly – Alexander Rakhmaev Oct 02 '20 at 07:59