Ask Your Question
1

embed sage vars in html notebook cell

asked 2012-12-01 07:53:18 +0100

PatrickSurry gravatar image

updated 2012-12-01 14:29:25 +0100

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?

edit retag flag offensive close merge delete

Comments

Another interesting directive that I just stumbled on and didn't see documented is %hide, which seems to hide the remainder of your input cell text

PatrickSurry gravatar imagePatrickSurry ( 2012-12-06 11:43:37 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2012-12-01 14:28:09 +0100

PatrickSurry gravatar image

Aha! 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:

%html
We can see that <sage>x</sage> is the key result

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?

edit flag offensive delete link more

Comments

That is awesome! I have never (or maybe very long ago?) seen this, so if it's not, it should be!

kcrisman gravatar imagekcrisman ( 2012-12-03 13:25:20 +0100 )edit

I'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.

kcrisman gravatar imagekcrisman ( 2012-12-03 13:31:41 +0100 )edit

Doing this in cloud.sagemath fails: x=2;%html; We can see that <sage>x</sage> is the key result

jeanpat gravatar imagejeanpat ( 2014-01-03 07:40:28 +0100 )edit
0

answered 2012-12-01 11:38:14 +0100

ppurka gravatar image

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

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-01 07:53:18 +0100

Seen: 597 times

Last updated: Dec 01 '12