Is it possible to show `print` output as LaTeX in jupyter notebook? Is it possible to show `print` output as LaTeX in jupyter notebook? python-3.x python-3.x

Is it possible to show `print` output as LaTeX in jupyter notebook?


Use IPython.display's display function with a Math object:

from IPython.display import display, Mathdisplay(Math(r'Dims: {}x{}m \\ Area: {}m^2 \\ Volume: {}m^3'.format(a, round(b,2), P, V)))

Note the use of Latex-style \\ newlines, and the r'' string, which will take the backslashes as literal backslashes and not see them as escape characters.

Found the solution here.


Here's another solution that let's you include text and math a little easier:Use Markdown with r (so backslashed don't become escape chars) and f stringfor value insertion.

from IPython.display import display, Markdowna = 13.49b = 2.2544223P = 302.99V = 90.02display(Markdown(   rf"""Dims: ${a}m \times{b:5.2}m$Area: ${P}m^2$Volume: ${V}m^3$"""))