currently I'm struggeling a little bit with the output from SymPy. By default, by executing the following (assuming using Jupyter Notebook):
from sympy import *
t, x = symbols('t x')
u = Function('u')(t, x)
display(Eq(I*u.diff(t) + u.diff(x,x) + abs(u)**2*u))
it prints
I want to have it like this, however
in order to increase readability. Has anyone a clue how to achieve this? I'm rather new to SymPy and really would like to get this output.
Looking forward to your answers!
EDIT1:
I took the suggestions from @smichr, tweaked it a little and wrote it into a function. Hopefully I covered everything important. Here is the function
# Assuming that symbols and functions with greek letters are defined like this
# omega = Function('\\omega')(t, x)
def show(expr):
functions = expr.atoms(Function)
reps = {}
for fun in functions:
# Consider the case that some functions won't have the name
# attribute e.g. Abs of an elementary function
try:
reps[fun] = Symbol(fun.name) # Otherwise functions with greek symbols aren't replaced
except AttributeError:
continue
dreps = [(deriv, Symbol(deriv.expr.subs(reps).name + "_{," +
''.join(par.name for par in deriv.variables) + "}")) \
for deriv in expr.atoms(Derivative)]
# Ensure that higher order derivatives are replaced first, then lower ones.
# Otherwise you get d/dr w_r instead of w_rr
dreps.sort(key=lambda x: len(x[0].variables), reverse=True)
output = expr.subs(dreps).subs(reps)
display(output)
zeta, eta = symbols('\\zeta \\eta')
psi = Function('\\psi')(zeta, eta)
eq = Eq(I*psi.diff(zeta) + psi.diff(eta, eta) + abs(psi)**2*psi, 0)
show(eq)