How to display sympy output in proper manner

Viewed 260

I am very new to coding in Python and using the django.

My question: is it possible to get the input-format of an output I get from previous calculations? For example, if I obtain an output is like x**2 how can I get x^2 (x superscript 2) automatically?

for example: i want this type of output.

def home(request):
    return render(request, 'home.html', {'name':"suchit"})

def add(request):
    sp.init_printing(use_latex=True)
    val1 = sp.symbols('val1')
    x = sp.symbols('x')
    val1 = (request.POST['num1'])
    # val2 = int(request.POST['num2'])
    # red = add('val1','val2')
    # init_printing()
    Differentiate = sp.diff(val1,x)
    Integrate = sp.integrate(val1,x)

    # result = [Differentiate,Integrate]
     # integral_steps(res)
    return render(request,'home.html',{'result': Differentiate, 'result1':  Integrate  })

    # return render(request, 'home.html ', {'name': 'add'})

OUTPUT is:-

x**2/2

i don't want to this type of output. i want to x superscript 2 /2 (x^2/2). check link to show that format.

1 Answers

sympy expressions can get pretty complicated so this gets very difficult in the general case. HTML has MathML for this but support is not great which complicates things

I'd therefore suggest generating LaTeX or MathML in SymPy and also pulling in MathJAX to make sure it renders correctly in more browsers

Related