Ask Your Question
1

Layouting of sage notebook

asked 2011-02-28 08:08:54 +0200

indiajoe gravatar image

updated 2011-03-03 04:52:43 +0200

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.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-03-02 15:48:04 +0200

niles gravatar image

updated 2011-03-03 09:44:15 +0200

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

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

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.

edit flag offensive delete link more

Comments

@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..

indiajoe gravatar imageindiajoe ( 2011-03-03 04:24:52 +0200 )edit

Thanks a lot. It worked perfectly...

indiajoe gravatar imageindiajoe ( 2011-03-04 06:13:32 +0200 )edit
1

answered 2011-03-03 10:21:28 +0200

DSM gravatar image

updated 2011-03-03 10:22:19 +0200

If 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

for me.

edit flag offensive delete link more

Comments

Thanks a lot both the methods worked..

indiajoe gravatar imageindiajoe ( 2011-03-04 06:12:53 +0200 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2011-02-28 08:08:54 +0200

Seen: 707 times

Last updated: Mar 03 '11