ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 24 Nov 2022 14:41:23 +0100sagemath displays in different lineshttps://ask.sagemath.org/question/65020/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 :)Wed, 23 Nov 2022 21:20:39 +0100https://ask.sagemath.org/question/65020/sagemath-displays-in-different-lines/Answer by achrzesz for <p>Hi there,</p>
<p>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:</p>
<p>eq2 = x*eq0</p>
<p>display(LatexExpr(r'\langle x \rangle = \int\limits_{-\infty}^\infty x\rho dx'))</p>
<p>x1 = eq2.rhs().integral(x, -infinity, infinity)</p>
<p>display(LatexExpr(r'\langle x\rangle = '), x1)</p>
<p>(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>
<p>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 :)</p>
https://ask.sagemath.org/question/65020/sagemath-displays-in-different-lines/?answer=65021#post-id-65021Maybe this example can help
%display latex
C=var('C')
show(integrate(tan(x),x,hold=True),'=', integrate(tan(x),x),'+',C)Wed, 23 Nov 2022 22:31:19 +0100https://ask.sagemath.org/question/65020/sagemath-displays-in-different-lines/?answer=65021#post-id-65021Comment by Flopsiturtle for <p>Maybe this example can help</p>
<pre><code>%display latex
C=var('C')
show(integrate(tan(x),x,hold=True),'=', integrate(tan(x),x),'+',C)
</code></pre>
https://ask.sagemath.org/question/65020/sagemath-displays-in-different-lines/?comment=65036#post-id-65036Thanks it works like thisThu, 24 Nov 2022 14:41:23 +0100https://ask.sagemath.org/question/65020/sagemath-displays-in-different-lines/?comment=65036#post-id-65036Answer by Juanjo for <p>Hi there,</p>
<p>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:</p>
<p>eq2 = x*eq0</p>
<p>display(LatexExpr(r'\langle x \rangle = \int\limits_{-\infty}^\infty x\rho dx'))</p>
<p>x1 = eq2.rhs().integral(x, -infinity, infinity)</p>
<p>display(LatexExpr(r'\langle x\rangle = '), x1)</p>
<p>(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>
<p>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 :)</p>
https://ask.sagemath.org/question/65020/sagemath-displays-in-different-lines/?answer=65025#post-id-65025Try 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](https://sagecell.sagemath.org/?z=eJydjkEKgzAQRfcF7zCELiY1oEi33iQoUmMNpCompSMhd--Ii9JNF2W27_15hpbVeG_nCWpYhe6tX1y3-bA5o-0U2rKJerHFNenQTUhSq56gFtmJtacLbDFl7msXDB6EAiRVql2SMjv5cX7hGB4OxVlADubzMYdBRMcm4bEm004wt4v7mV95zj7aSDrMUCY9rN0tam-npkIOBpIpUlOlr1Q2bECGcLEXkk1VMKKA6vL_0DdpJ2h5&lang=sage&interacts=eJyLjgUAARUAuQ==)Thu, 24 Nov 2022 03:28:27 +0100https://ask.sagemath.org/question/65020/sagemath-displays-in-different-lines/?answer=65025#post-id-65025