# How to render Latex markup using Python?

## How to render Latex markup using Python?

As suggested by Andrew little work around using matplotlib.

```
import matplotlib.pyplot as plt
a = \frac{a}{b} #notice escaped slash
plt.plot()
plt.text(0.5, 0.5,$%s$%a)
plt.show()
```

An answer based on this one specific to Jupyter notebook, using f-string to format an `$x_i$`

variable:

```
from IPython.display import display, Latex
for i in range(3):
display(Latex(f$x_{i}$))
```

**Note:** The f-string (formatted string literal) uses curly braces to insert the value of the Python variable `i`

. You’ll need to double the curly braces (`f{{}}`

) to actually use `{}`

in the LaTeX code. Otherwise, you can use single curly braces directly in a normal Python string (not an f-string).

**Side Note:** Im surprised Stack Overflow still doesn’t have a math markup.

#### How to render Latex markup using Python?

Creating mathematical formulas in Pandas.

```
a = rfrac{a}{b}
ax = plt.axes([0,0,0.3,0.3]) #left,bottom,width,height
ax.set_xticks([])
ax.set_yticks([])
ax.axis(off)
plt.text(0.4,0.4,$%s$ %a,size=50,color=green)
```

```
a = rf(x) = frac{exp(-x^2/2)}{sqrt{2*pi}}
ax = plt.axes([0,0,0.3,0.3]) #left,bottom,width,height
ax.set_xticks([])
ax.set_yticks([])
ax.axis(off)
plt.text(0.4,0.4,$%s$ %a,size=50,color=green)
```