ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 03 Jan 2014 00:40:28 -0600embed sage vars in html notebook cellhttp://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/Again I feel like I'm missing something. I'm trying to add some mostly text content to a notebook cell, but I want to include an equation contained in a notebook variable. For example I have defined
var('u, v, w')
x = u * v * w^2
And then I want to write a few paragraphs that includes the formula contained in x.
If I use the HTML editor and put something in dollar signs, it formats as math but doesn't eval the content, i.e. if I say $x$ then I just get a literal x in italics.
If I call the html() function, I can do something like `html('testing $'+latex(x)+'$')` to manually substitute myself, but this gets formatted in fixed-width font for reasons I don't understand.
If I start a cell with `%html`, then I can't figure out how to get the latex/html representation of the formula in x, but otherwise it formats it nicely. (I guess like an HTML editor cell)
Also, is there some documentation of how the different cell tags like %latex, %html, etc work?
Sat, 01 Dec 2012 00:53:18 -0600http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/Comment by PatrickSurry for <p>Again I feel like I'm missing something. I'm trying to add some mostly text content to a notebook cell, but I want to include an equation contained in a notebook variable. For example I have defined</p>
<pre><code>var('u, v, w')
x = u * v * w^2
</code></pre>
<p>And then I want to write a few paragraphs that includes the formula contained in x. </p>
<p>If I use the HTML editor and put something in dollar signs, it formats as math but doesn't eval the content, i.e. if I say $x$ then I just get a literal x in italics. </p>
<p>If I call the html() function, I can do something like <code>html('testing $'+latex(x)+'$')</code> to manually substitute myself, but this gets formatted in fixed-width font for reasons I don't understand.</p>
<p>If I start a cell with <code>%html</code>, then I can't figure out how to get the latex/html representation of the formula in x, but otherwise it formats it nicely. (I guess like an HTML editor cell)</p>
<p>Also, is there some documentation of how the different cell tags like %latex, %html, etc work?</p>
http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?comment=18578#post-id-18578Another interesting directive that I just stumbled on and didn't see documented is %hide, which seems to hide the remainder of your input cell textThu, 06 Dec 2012 04:43:37 -0600http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?comment=18578#post-id-18578Answer by PatrickSurry for <p>Again I feel like I'm missing something. I'm trying to add some mostly text content to a notebook cell, but I want to include an equation contained in a notebook variable. For example I have defined</p>
<pre><code>var('u, v, w')
x = u * v * w^2
</code></pre>
<p>And then I want to write a few paragraphs that includes the formula contained in x. </p>
<p>If I use the HTML editor and put something in dollar signs, it formats as math but doesn't eval the content, i.e. if I say $x$ then I just get a literal x in italics. </p>
<p>If I call the html() function, I can do something like <code>html('testing $'+latex(x)+'$')</code> to manually substitute myself, but this gets formatted in fixed-width font for reasons I don't understand.</p>
<p>If I start a cell with <code>%html</code>, then I can't figure out how to get the latex/html representation of the formula in x, but otherwise it formats it nicely. (I guess like an HTML editor cell)</p>
<p>Also, is there some documentation of how the different cell tags like %latex, %html, etc work?</p>
http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?answer=14336#post-id-14336Aha! I did some code exploration of sage/misc/html.py and discovered the `<sage>` tag, so you can just write something like this in a a cell:
<pre>
%html
We can see that <sage>x</sage> is the key result
</pre>
and it will do sage_eval() and format the result in math mode, so you get nice inline math display of the formula contained in x. That is exactly what I need - is that `<sage>` tag documented anywhere?Sat, 01 Dec 2012 07:28:09 -0600http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?answer=14336#post-id-14336Comment by kcrisman for <p>Aha! I did some code exploration of sage/misc/html.py and discovered the <code><sage></code> tag, so you can just write something like this in a a cell:</p>
<pre>%html
We can see that <sage>x</sage> is the key result
</pre>
<p>and it will do sage_eval() and format the result in math mode, so you get nice inline math display of the formula contained in x. That is exactly what I need - is that <code><sage></code> tag documented anywhere?</p>
http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?comment=18593#post-id-18593I've followed up at http://groups.google.com/group/sage-notebook/browse_thread/thread/df60dc6f9e9fea06 with a question about this, thank you very much for finding it.Mon, 03 Dec 2012 06:31:41 -0600http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?comment=18593#post-id-18593Comment by kcrisman for <p>Aha! I did some code exploration of sage/misc/html.py and discovered the <code><sage></code> tag, so you can just write something like this in a a cell:</p>
<pre>%html
We can see that <sage>x</sage> is the key result
</pre>
<p>and it will do sage_eval() and format the result in math mode, so you get nice inline math display of the formula contained in x. That is exactly what I need - is that <code><sage></code> tag documented anywhere?</p>
http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?comment=18594#post-id-18594That is awesome! I have never (or maybe very long ago?) seen this, so if it's not, it should be!Mon, 03 Dec 2012 06:25:20 -0600http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?comment=18594#post-id-18594Comment by jeanpat for <p>Aha! I did some code exploration of sage/misc/html.py and discovered the <code><sage></code> tag, so you can just write something like this in a a cell:</p>
<pre>%html
We can see that <sage>x</sage> is the key result
</pre>
<p>and it will do sage_eval() and format the result in math mode, so you get nice inline math display of the formula contained in x. That is exactly what I need - is that <code><sage></code> tag documented anywhere?</p>
http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?comment=16478#post-id-16478Doing this in cloud.sagemath fails: x=2;%html;
We can see that <sage>x</sage> is the key resultFri, 03 Jan 2014 00:40:28 -0600http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?comment=16478#post-id-16478Answer by ppurka for <p>Again I feel like I'm missing something. I'm trying to add some mostly text content to a notebook cell, but I want to include an equation contained in a notebook variable. For example I have defined</p>
<pre><code>var('u, v, w')
x = u * v * w^2
</code></pre>
<p>And then I want to write a few paragraphs that includes the formula contained in x. </p>
<p>If I use the HTML editor and put something in dollar signs, it formats as math but doesn't eval the content, i.e. if I say $x$ then I just get a literal x in italics. </p>
<p>If I call the html() function, I can do something like <code>html('testing $'+latex(x)+'$')</code> to manually substitute myself, but this gets formatted in fixed-width font for reasons I don't understand.</p>
<p>If I start a cell with <code>%html</code>, then I can't figure out how to get the latex/html representation of the formula in x, but otherwise it formats it nicely. (I guess like an HTML editor cell)</p>
<p>Also, is there some documentation of how the different cell tags like %latex, %html, etc work?</p>
http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?answer=14327#post-id-14327I don't think there is any straightforward way to display dynamically evaluated expressions. You can use a combination of the html command and the `pretty_print` command. The output does seem to have monospaced fonts.
var('u,v,w')
x = u^2 + v^2 + w + integral(e^(u^2), u)
html('The output:')
pretty_print(x)
html('Is it correct?')
Not sure about the documentation of those %latex, %html functions.Sat, 01 Dec 2012 04:38:14 -0600http://ask.sagemath.org/question/9594/embed-sage-vars-in-html-notebook-cell/?answer=14327#post-id-14327