Ask Your Question
0

Can I display a list of equations aligned like latex eqnarray?

asked 2012-12-03 16:30:07 +0200

PatrickSurry gravatar image

I have several sage equations stored in a python list (for use in solve() etc). I'd like to display them one per line, aligned on equal signs if possible. This is in the notebook.

Most things I've tried - view(), show(), pretty_print() just print something that looks like a python list of formatted equations, all on one line (although the documentation for view() claims it will print each element of a list on a separate line, that doesn't seem to be the case).

The only things I've come up with are to explicitly loop, like: for eqn in eqns: view(eqn) or to pass eqns to html.table() which does one per line with alternating line shading.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2012-12-04 04:32:43 +0200

ndomes gravatar image

updated 2012-12-04 12:22:47 +0200

You can use html.table placing left hand side, equal sign and right hand side in separate columns.

var('x y z alpha')
eqns = [x == y^2, z+alpha^3 == 0]
table = [ (eq.lhs(),'=',eq.rhs()) for eq in eqns ]
html.table(table)
edit flag offensive delete link more

Comments

That's a good idea. If you add a %html cell you can improve the styling: avoid the alternating grey rows, tighten up the spacing, and right-align the leftmost column. I used this: %html <style> table.table_form * tr.row-a { background: #ffffff; } table.table_form * tr.row-b { background: #ffffff; } table.table_form * td { padding-top: 5px; padding-bottom: 5px; padding-left: 2px; padding-right: 2px; } table.table_form tr td:first-child { text-align: right; } </style>

PatrickSurry gravatar imagePatrickSurry ( 2012-12-04 06:50:28 +0200 )edit

You don't need a %html cell, I tried: html(""" <style> .row-a td:first-child {text-align:right;} .row-b td:first-child {text-align:right;} </style> """) inside a sage cell and it worked well.

ndomes gravatar imagendomes ( 2012-12-04 12:21:25 +0200 )edit

Makes sense. Tho I've started doing all my text as %html so I can use the <sage> tags and avoid the pre-formatted (fixed width) text I seem to get with html()

PatrickSurry gravatar imagePatrickSurry ( 2012-12-04 22:46:22 +0200 )edit
0

answered 2012-12-03 21:28:41 +0200

This doesn't look too bad:

sage: var('x y z alpha')
sage: L = [x == y^2, z+alpha^3 == 0]
view(L, viewer='pdf')

Alignment on equals signs is trickier, but the following works in the notebook. With L as above, create a cell containing this:

%latex
Here are the equations:
\begin{align*}
\sage{L[0].left_hand_side()} &= \sage{L[0].right_hand_side()} \\
\sage{L[1].left_hand_side()} &= \sage{L[1].right_hand_side()}
\end{align*}

There is probably a way to autogenerate this code in the notebook.

The patch at http://trac.sagemath.org/sage_trac/ti... might also help.

edit flag offensive delete link more

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: 2012-12-03 16:30:07 +0200

Seen: 2,195 times

Last updated: Dec 04 '12