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.Fri, 04 Mar 2011 06:13:32 +0100Layouting of sage notebookhttps://ask.sagemath.org/question/7976/layouting-of-sage-notebook/Hi,
I want to take a printout of the notebook output. But since the eqns sage calculated are too large, it wrote the entire equation in a single line.
I am not able to take a printout of my notebook because of this single line output.
Is there any way, I can make sage output the results in a specified width. So that I can take printout on normal A4 Size papers?
Thanking in advance.
-indiajoe
Update:
The notebook I am having trouble is the one in the following published page.
http://480.sagenb.org/home/pub/60/
The notorious long eqn is the one at the end of the first cell. I am not able to make them print in multiple lines.Mon, 28 Feb 2011 08:08:54 +0100https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/Answer by niles for <p>Hi,
I want to take a printout of the notebook output. But since the eqns sage calculated are too large, it wrote the entire equation in a single line.
I am not able to take a printout of my notebook because of this single line output.
Is there any way, I can make sage output the results in a specified width. So that I can take printout on normal A4 Size papers?
Thanking in advance.
-indiajoe</p>
<p>Update:</p>
<p>The notebook I am having trouble is the one in the following published page.</p>
<p><a href="http://480.sagenb.org/home/pub/60/">http://480.sagenb.org/home/pub/60/</a></p>
<p>The notorious long eqn is the one at the end of the first cell. I am not able to make them print in multiple lines.</p>
https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?answer=12162#post-id-12162If you can see a reasonable way to split the equation up, you could have sage store the pieces in separate variables and print them separately . . . but the obvious example I tried
sum(i*x**i for i in range(30))
automatically prints on several different lines anyway.
For your case, if you change the definition of `f` to
f= A2*Term1 + B2*Term2 == (42/10)**2
and change the last part to
newf=f(k=kvalue)
newg=g(k=kvalue)
opf = newf.lhs().operands()
show(opf[0])
print("+")
show(opf[1]==newf.rhs())
show(newg)
you'll get something like
![image description](/upfiles/12991632056518308.png)
This could maybe be improved a little, but illustrates two key things:
* use `.operands()` to split an equation or symbolic expression into pieces which you can print separately
* the additional zeroes are coming from the precision of the real numbers you're working with (53 bits by default, I think). If you use rationals instead, you'll get exact values, or you could use lower-precision real numbers.Wed, 02 Mar 2011 15:48:04 +0100https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?answer=12162#post-id-12162Comment by indiajoe for <p>If you can see a reasonable way to split the equation up, you could have sage store the pieces in separate variables and print them separately . . . but the obvious example I tried</p>
<pre><code>sum(i*x**i for i in range(30))
</code></pre>
<p>automatically prints on several different lines anyway. </p>
<p>For your case, if you change the definition of <code>f</code> to</p>
<pre><code>f= A2*Term1 + B2*Term2 == (42/10)**2
</code></pre>
<p>and change the last part to</p>
<pre><code>newf=f(k=kvalue)
newg=g(k=kvalue)
opf = newf.lhs().operands()
show(opf[0])
print("+")
show(opf[1]==newf.rhs())
show(newg)
</code></pre>
<p>you'll get something like</p>
<p><img alt="image description" src="/upfiles/12991632056518308.png"/></p>
<p>This could maybe be improved a little, but illustrates two key things:</p>
<ul>
<li><p>use <code>.operands()</code> to split an equation or symbolic expression into pieces which you can print separately</p></li>
<li><p>the additional zeroes are coming from the precision of the real numbers you're working with (53 bits by default, I think). If you use rationals instead, you'll get exact values, or you could use lower-precision real numbers.</p></li>
</ul>
https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?comment=22027#post-id-22027@niles: Thanks for looking into my layout problem. I have updated the question with the link to the published example. It has the long eqn which is creating problem at the end of the first cell. The eqn is printing lot of unwanted zeros also. I don't know how to remove that too. Thanks again..Thu, 03 Mar 2011 04:24:52 +0100https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?comment=22027#post-id-22027Comment by indiajoe for <p>If you can see a reasonable way to split the equation up, you could have sage store the pieces in separate variables and print them separately . . . but the obvious example I tried</p>
<pre><code>sum(i*x**i for i in range(30))
</code></pre>
<p>automatically prints on several different lines anyway. </p>
<p>For your case, if you change the definition of <code>f</code> to</p>
<pre><code>f= A2*Term1 + B2*Term2 == (42/10)**2
</code></pre>
<p>and change the last part to</p>
<pre><code>newf=f(k=kvalue)
newg=g(k=kvalue)
opf = newf.lhs().operands()
show(opf[0])
print("+")
show(opf[1]==newf.rhs())
show(newg)
</code></pre>
<p>you'll get something like</p>
<p><img alt="image description" src="/upfiles/12991632056518308.png"/></p>
<p>This could maybe be improved a little, but illustrates two key things:</p>
<ul>
<li><p>use <code>.operands()</code> to split an equation or symbolic expression into pieces which you can print separately</p></li>
<li><p>the additional zeroes are coming from the precision of the real numbers you're working with (53 bits by default, I think). If you use rationals instead, you'll get exact values, or you could use lower-precision real numbers.</p></li>
</ul>
https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?comment=22025#post-id-22025Thanks a lot. It worked perfectly...Fri, 04 Mar 2011 06:13:32 +0100https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?comment=22025#post-id-22025Answer by DSM for <p>Hi,
I want to take a printout of the notebook output. But since the eqns sage calculated are too large, it wrote the entire equation in a single line.
I am not able to take a printout of my notebook because of this single line output.
Is there any way, I can make sage output the results in a specified width. So that I can take printout on normal A4 Size papers?
Thanking in advance.
-indiajoe</p>
<p>Update:</p>
<p>The notebook I am having trouble is the one in the following published page.</p>
<p><a href="http://480.sagenb.org/home/pub/60/">http://480.sagenb.org/home/pub/60/</a></p>
<p>The notorious long eqn is the one at the end of the first cell. I am not able to make them print in multiple lines.</p>
https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?answer=12168#post-id-12168If you're willing to accept a change in size and slight difference in appearance, you could try defining
show2 = sage.misc.latex.pretty_print
and then using
show2(newf)
which produces
![example compressed equation](/upfiles/1299165724212727.png)
for me.Thu, 03 Mar 2011 10:21:28 +0100https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?answer=12168#post-id-12168Comment by indiajoe for <p>If you're willing to accept a change in size and slight difference in appearance, you could try defining</p>
<pre><code>show2 = sage.misc.latex.pretty_print
</code></pre>
<p>and then using</p>
<pre><code>show2(newf)
</code></pre>
<p>which produces</p>
<p><img alt="example compressed equation" src="/upfiles/1299165724212727.png"/></p>
<p>for me.</p>
https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?comment=22026#post-id-22026Thanks a lot both the methods worked..Fri, 04 Mar 2011 06:12:53 +0100https://ask.sagemath.org/question/7976/layouting-of-sage-notebook/?comment=22026#post-id-22026