# sagemath displays in different lines

Hi there,

I am trying to display two different things at once. The first is some Latex stuff, and the second is the solution to a symbolic integration done in sage. Here is the code:

eq2 = x*eq0

display(LatexExpr(r'\langle x \rangle = \int\limits_{-\infty}^\infty x\rho dx'))

x1 = eq2.rhs().integral(x, -infinity, infinity)

display(LatexExpr(r'\langle x\rangle = '), x1)

(sorry I don't know how to show my code in a better format) so what happens is, that the latex expression is displayed in the first line and x1 is displayed in the second line. I hope someone can help me with this.

P.S.: is there a way to display the integral itself and not only the solution? I avoided this problem by just writing the latex expression manually in the first line. Thanks in advance for your help :)

edit retag close merge delete

Sort by » oldest newest most voted

Maybe this example can help

%display latex
C=var('C')
show(integrate(tan(x),x,hold=True),'=', integrate(tan(x),x),'+',C)

more

Thanks it works like this

( 2022-11-24 14:41:23 +0100 )edit

Try the following examples:

expression = r"\displaystyle\int_0^{\pi/4}\tan(x)\,dx ="
result = integrate(tan(x), (x,0,pi/4))
show(html("$" + expression + f"{latex(result)}" + "$"))

expression = r"\displaystyle\lim_{x\to 0}\frac{\sin^2(\pi x)}{x^2}="
result = limit(sin(pi*x)^2/x^2, x=0)
show(html("$" + expression + f"{latex(result)}" + "$"))


They are shown in this SageMath Cell

more