Ask Your Question
0

sagemath displays in different lines

asked 2 years ago

Flopsiturtle gravatar image

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 :)

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 2 years ago

achrzesz gravatar image

updated 2 years ago

Maybe this example can help

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

Comments

Thanks it works like this

Flopsiturtle gravatar imageFlopsiturtle ( 2 years ago )
0

answered 2 years ago

Juanjo gravatar image

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

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2 years ago

Seen: 374 times

Last updated: Nov 24 '22