# Display command output as math : IPython.display.Math?

**URL:** <https://discourse.jupyter.org/t/display-command-output-as-math-ipython-display-math/3125>\
**Category:** JupyterLab\
**Created:** [January 23, 2020, 10:30am UTC](https://discourse.jupyter.org/t/display-command-output-as-math-ipython-display-math/3125 "2020-01-23T10:30:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fomightez](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/fomightez/32/495_2.png) [@fomightez](https://discourse.jupyter.org/u/fomightez)\
**Post date:** [January 23, 2020, 4:36pm UTC](https://discourse.jupyter.org/t/display-command-output-as-math-ipython-display-math/3125/2 "2020-01-23T16:36:38Z")

</div>

Building on my example from [here](https://discourse.jupyter.org/t/how-to-add-markdown-inside-a-function-to-pretty-print-equation/2719/2) that works in JupyterLab, I converted your code. Works in current JupyterLab:

```python
from IPython.display import Markdown, display
def printmd(string):
    display(Markdown(string))
import sympy as sym
x = sym.symbols('x')
I = sym.integrate(1/(1+x**2), (x, 0, 1))
equation = r'$$\int_{{t=0}}^1 \frac{{1}}{{1+t^2}}\,\text{d}t$$'
printmd(' **THE EQUATION:**')
printmd(f'{equation}')
printmd(' **THE RESULT:**')
printmd(f'$$ = {sym.latex(I)}$$')
printmd(' **COMBINED:**')
printmd(r'$$\int_{{t=0}}^1 \frac{{1}}{{1+t^2}}\,\text{d}t' + f' = {sym.latex(I)}$$')
printmd(' **OR, COMBINED:**')
printmd(equation[:-2] + f' = {sym.latex(I)}$$') #alternative way to leave off right-side dollar signs

```

Related notes: Python’s new f-strings are awesome; however, mixing [f-strings](https://realpython.com/python-f-strings/) (and even the [`str.format()` method](https://pyformat.info/)) with integral notation is a bit of a nightmare because of the braces. And just best avoided, if possible. Luckily, you weren’t substituting in the left side, but I imagine approaches like [this](https://dpb.bitbucket.io/data-within-literal-curly-brackets-using-python-format.html) will help with that. In current versions of Jupyter, both JupyterLab and the classic interface you can use dollar signs to ‘fence’ LaTeX code **in markdown cells** and have it rendered in the notebook via MathJax. The trick I show there making a `printmd()` function just brings the markdown rendering to the code cells as well.

---

_[View the full topic](https://discourse.jupyter.org/t/display-command-output-as-math-ipython-display-math/3125)._
