ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 28 Sep 2012 10:39:19 -0500print LaTeX in notebook from scripthttps://ask.sagemath.org/question/9357/print-latex-in-notebook-from-script/I've read through
www.sagemath.org/doc/tutorial/latex.html
but still can't seem to find the equivalent to using "view" or "pretty-print" to display equations at LaTeX in a notebook cell when running a Python script from the notebook. (I do have "Typeset" checked at the start of the notebook.) For example, suppose my file foo.py has a function:
def show_all(self):
y = var('y')
x = 2.0*y**2
view(x)
pretty_print(x)
show(x)
JSMath()(x)
JSMath().eval(x)
print JSMath()(x)
print JSMath().eval(x)
html(JSMath()(x))
html(JSMath().eval(x))
print html(JSMath()(x))
print html(JSMath().eval(x))
Running this function from a notebook cell returns lines of the form either
\newcommand{\Bold}[1]{\mathbf{#1}}2.0 \, y^{2}
or
\newcommand{\Bold}[1]{\mathbf{#1}}2.0 \, y^{2}
</font></html>
But I just want a nice LaTeX display of 2*y***2 equivalent to typing (from a notebook cell)
view(2.0*y**2)
which returns
2.00000000000000y2 (prettier than this of course)
So I'm still missing the right combination of LaTeX library functions. As a follow-up question, is dealing with LaTeX macros the only way to get the "2.00000000000" in the above to display as 2.0, 2.00, etc.?Thu, 27 Sep 2012 12:35:22 -0500https://ask.sagemath.org/question/9357/print-latex-in-notebook-from-script/Answer by John Palmieri for <p>I've read through </p>
<p><a href="http://www.sagemath.org/doc/tutorial/latex.html">www.sagemath.org/doc/tutorial/latex.html</a> </p>
<p>but still can't seem to find the equivalent to using "view" or "pretty-print" to display equations at LaTeX in a notebook cell when running a Python script from the notebook. (I do have "Typeset" checked at the start of the notebook.) For example, suppose my file foo.py has a function:</p>
<pre><code>def show_all(self):
y = var('y')
x = 2.0*y**2
view(x)
pretty_print(x)
show(x)
JSMath()(x)
JSMath().eval(x)
print JSMath()(x)
print JSMath().eval(x)
html(JSMath()(x))
html(JSMath().eval(x))
print html(JSMath()(x))
print html(JSMath().eval(x))
</code></pre>
<p>Running this function from a notebook cell returns lines of the form either</p>
<pre><code> \newcommand{\Bold}[1]{\mathbf{#1}}2.0 \, y^{2}
</code></pre>
<p>or </p>
<pre><code> \newcommand{\Bold}[1]{\mathbf{#1}}2.0 \, y^{2}
</font></html>
</code></pre>
<p>But I just want a nice LaTeX display of 2<em>y</em>**2 equivalent to typing (from a notebook cell)</p>
<pre><code>view(2.0*y**2)
</code></pre>
<p>which returns</p>
<pre><code>2.00000000000000y2 (prettier than this of course)
</code></pre>
<p>So I'm still missing the right combination of LaTeX library functions. As a follow-up question, is dealing with LaTeX macros the only way to get the "2.00000000000" in the above to display as 2.0, 2.00, etc.?</p>
https://ask.sagemath.org/question/9357/print-latex-in-notebook-from-script/?answer=14074#post-id-14074I think you need to upgrade your version of Sage. Many of the commands in your script work for me, either with Sage on my own computer or with [sagenb on line](http://www.sagenb.org). For example,
def show_all():
y = var('y')
x = 2.0*y**2
view(x)
pretty_print(x)
show(x)
print MathJax()(x)
prints `x` nicely four times.
For decimal expansions, you can force the coefficient to have lower precision:
def show_all():
y = var('y')
x = 2.0*y**2
view(x)
a = RDF(2.0)
a = a.n(digits=3)
x = a*y**2
view(x)
For me, this prints "2.00000000000000y^2" and "2.00y^2" (formatted nicely).
Fri, 28 Sep 2012 08:33:54 -0500https://ask.sagemath.org/question/9357/print-latex-in-notebook-from-script/?answer=14074#post-id-14074Comment by burningbright for <p>I think you need to upgrade your version of Sage. Many of the commands in your script work for me, either with Sage on my own computer or with <a href="http://www.sagenb.org">sagenb on line</a>. For example,</p>
<pre><code>def show_all():
y = var('y')
x = 2.0*y**2
view(x)
pretty_print(x)
show(x)
print MathJax()(x)
</code></pre>
<p>prints <code>x</code> nicely four times.</p>
<p>For decimal expansions, you can force the coefficient to have lower precision:</p>
<pre><code>def show_all():
y = var('y')
x = 2.0*y**2
view(x)
a = RDF(2.0)
a = a.n(digits=3)
x = a*y**2
view(x)
</code></pre>
<p>For me, this prints "2.00000000000000y^2" and "2.00y^2" (formatted nicely).</p>
https://ask.sagemath.org/question/9357/print-latex-in-notebook-from-script/?comment=18985#post-id-18985I'm using Sage version 5.2. Will post an update when I get 5.3 installed. Thanks.Fri, 28 Sep 2012 10:39:19 -0500https://ask.sagemath.org/question/9357/print-latex-in-notebook-from-script/?comment=18985#post-id-18985