together print latex formula and value of variable

27 views
Skip to first unread message

Sandor Szabo

unread,
Oct 28, 2017, 7:53:30 AM10/28/17
to Project Jupyter
Hi,

In Jupyter Notebook the code

print( "f(x,x^2)=",  f(x, x**2) )

gives the output

f(x,x^2)= 1/2

Instead of   f(x,x^2) I would like to obtain

           2
  f(x, x ).

How does it possible to put LaTeX code into print command and print the nice
output and the value of a calculated variable?
I tried Eq( a, b), but I'm not satisfied with it.

Sandor

Damon Allen

unread,
Oct 29, 2017, 4:11:59 AM10/29/17
to Project Jupyter
There is the extension Py2Tex, but I don't know if it still works with the current Jupyter Notebooks since it was last updated four years ago.  Repository for extension.

Sandor Szabo

unread,
Oct 30, 2017, 6:03:26 AM10/30/17
to Project Jupyter
Thanks for the suggestion. I try to find an alternate solution, maybe asking in other forum.

Johannes Feist

unread,
Oct 30, 2017, 7:17:37 AM10/30/17
to jup...@googlegroups.com
If you are happy with writing the Latex string yourself, you can simply use the latex display capability of Jupyter / IPython (combined with normal python string formatting to include variable values etc), e.g. with

from IPython.display import Latex, display_latex
x = 3.65
display_latex("$x^2 = %g$"%x, raw=True)

or, equivalently, with 

display(Latex("$x^2 = %g$"%x))

If the Latex object is the last line in your cell, it will be displayed automatically. If you are not using ipython, but a different kernel, you have to find out how to produce objects with a LaTeX representation (e.g., Julia has https://github.com/stevengj/LaTeXStrings.jl).

Best,
Johannes


--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/afb30055-4895-4fef-bbf1-db90a7b79ddf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Johannes Feist
IFIMAC & Departamento de Física Teórica de la Materia Condensada
Universidad Autónoma de Madrid
johanne...@uam.es

Sandor Szabo

unread,
Oct 30, 2017, 7:31:57 AM10/30/17
to Project Jupyter
Thanks. Your solution is the easiest and simplest.
(In the meantime I found some module which hopefully could do the same task, but I will use your solution.)

Best,
Sandor
Reply all
Reply to author
Forward
0 new messages