Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Pretty print output in Jupyter notebook

In order to provide meaningful results to my students in a Jupyter notebook, I would like to pretty print some output, including text, LaTeX and things computed by Sage. I have found that I could combine either show (or pretty_print) and html, or show and LatexExpr. For example, either

limit = r"\displaystyle\lim_{x\to0}\frac{\sin x}{x}="
value = lim(sin(x)/x, x=0)
show(html("Solucion: "+"${}={}$".format(limit,value)))

or, instead,

limit = r"\displaystyle\lim_{x\to0}\frac{\sin x}{x}="
value = lim(sin(x)/x, x=0)
show("Solucion: ", LatexExpr(limit), value)

I would ask the following questions:

  1. Is there any reason to prefer one approach to the other?
  2. If I replace "Solucion" by "Solución" (please note the accented ó), which is the correct way to write this Spanish word, in both approaches I get meaningless letters instead of the expected output. If I use u"Solución", then Sage raises the error 'ascii' codec can't encode character u'\xf3' in position 6: ordinal not in range(128). Is there a way to use non-English characters?

I am using SageMath 8.5 on a MacBook Pro with macOS High Sierra.