Reputation: 8271
I want to show the result of an intergation, done in SymPy as an Output in Jupyter with MathJax. Everything works, but I wanted to adjust the output a bit, so that instead of the following:
I would get this output:
(Please ignore the arctan() thing.)
I have tried to achieve this by doing something like that:
from IPython.display import Math
from sympy.interactive import printing
printing.init_printing(use_latex=True)
f=(-2*x-1)/(pow(x,2)+2)
Math('F(x)=')
integrate(f,x)
Math('+C')
But unfortunately only the last output of the cell is shown, so my question is if it is possible to merge multiple outputs into one?
Upvotes: 1
Views: 992
Reputation: 305
You might also want to try looking at the "Display Math Operation" function I have been fiddling with. You can try it on mybinder:. It accepts things like
dmo(p = n*R*T/V)
makes the assignment to p
and outputs a typeset version of the latex string p=\frac{nRT}{V}
. The eventual goal is to get dmo(diff(p,T))
to output a typeset version of \frac{\partial p}{\partial T} = \frac{nR}{V}
. When I have more time, I am going to dig into the rendering in sympy and see if I can get options put into the actual operations, such as diff
and int
. The special Derivative
and Integrate
operations were also designed for rendering just those operations.
Follow the link in binder to the github repository if you have specific comments or suggestions.
Upvotes: 0
Reputation: 3682
You can use printing.default_latex
, which returns the expression in LaTex as a string:
from IPython.display import Math
import sympy
from sympy.interactive import printing
x = sympy.var('x')
f=(-2*x-1)/(pow(x,2)+2)
Math('F(x) = {} + C'.format(printing.default_latex(sympy.integrate(f, x))))
Upvotes: 3