# Is there a function to render latex or html in a notebook from a string ?

 0 Some user-interface method are: set the "typeset" flag at the top of the notebook. Use %html or %latex in the beginning of a cell. Use "shift+click" to open a new "tinymce" cell (for both: latex and html and more) or code can be called like: view(...some sage expression...): to produce rendered latex print '...some html...no latex....': renders html without latex I'm looking for a "render" command like render('< html > < b > Header < /b > < p >Some $x ^ 2$ formula< /p >< /html >') for mix html and latex formulas. Maybe calling tinymce functionality from my code, but how ? Header Some $x ^ 2$ formula. asked Nov 20 '10 Pedro Cruz 135 ● 4 ● 7 ● 16 http://www.mat.ua.pt/jped...

 8 Does this do what you want? html('Header

Some $x^2$ formula

')  (Don't include  and  tags.) You could use 

, for example, instead of .... You can even leave out the 

: html('

Some $x^2$ formula')  posted Nov 20 '10 John Palmieri 2880 ● 9 ● 25 ● 65 http://www.math.washingto... The html( ..string...) command uses jsmath to produce the output. However, the mark "%latex" on the top of the cell uses the full latex compiler to produce the output. What is the sage command to do the same effect ? For example: latex(..sageobj..) is used for printing a latex representation of a sageobject. I'm looking for a (%latex)(...text...) command that calls the latex compiler and shows an image of the output. Pedro Cruz (Jan 11 '11) There doesn't seem to be anything built in, but see my other answer. John Palmieri (Jan 31 '11)
 3 Try this: def compile_latex(s): """ Compile string s using LaTeX, and display a png picture of the output. """ from sage.misc.misc import tmp_dir, graphics_filename from sage.misc.latex import _run_latex_, LATEX_HEADER import os, shutil base_dir = os.path.abspath("") png_file = graphics_filename(ext='png') png_link = "cell://" + png_file tmp = tmp_dir() tmp = tmp_dir('sage_viewer') tex_file = os.path.join(tmp, "sage.tex") tmp_png_file = os.path.join(tmp, "sage.png") latex_code = LATEX_HEADER + '\n\\begin{document}\n' + s + '\\end{document}' open(tex_file, 'w').write(latex_code) e = _run_latex_(tex_file, png=True) if e.find("Error") == -1: shutil.copy(tmp_png_file, os.path.join(base_dir, png_file)) print ''%png_link return  Then run it with compile_string('some math: $x=y$. Some more: $x^2 = y^2$.'). posted Jan 31 '11 John Palmieri 2880 ● 9 ● 25 ● 65 http://www.math.washingto...

[hide preview]