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.Tue, 04 Dec 2012 22:46:22 +0100Can I display a list of equations aligned like latex eqnarray?https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/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.Mon, 03 Dec 2012 16:30:07 +0100https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/Answer by John Palmieri for <p>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.</p>
<p>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).</p>
<p>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.</p>
https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?answer=14344#post-id-14344This 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/ticket/13131 might also help.Mon, 03 Dec 2012 21:28:41 +0100https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?answer=14344#post-id-14344Answer by ndomes for <p>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.</p>
<p>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).</p>
<p>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.</p>
https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?answer=14345#post-id-14345You 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)Tue, 04 Dec 2012 04:32:43 +0100https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?answer=14345#post-id-14345Comment by ndomes for <p>You can use <strong>html.table</strong> placing left hand side, equal sign and right hand side in separate columns.</p>
<pre><code>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)
</code></pre>
https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?comment=18587#post-id-18587You 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.Tue, 04 Dec 2012 12:21:25 +0100https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?comment=18587#post-id-18587Comment by PatrickSurry for <p>You can use <strong>html.table</strong> placing left hand side, equal sign and right hand side in separate columns.</p>
<pre><code>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)
</code></pre>
https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?comment=18585#post-id-18585Makes 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()Tue, 04 Dec 2012 22:46:22 +0100https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?comment=18585#post-id-18585Comment by PatrickSurry for <p>You can use <strong>html.table</strong> placing left hand side, equal sign and right hand side in separate columns.</p>
<pre><code>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)
</code></pre>
https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?comment=18588#post-id-18588That'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>
Tue, 04 Dec 2012 06:50:28 +0100https://ask.sagemath.org/question/9603/can-i-display-a-list-of-equations-aligned-like-latex-eqnarray/?comment=18588#post-id-18588