How to render Latex markup using Python?

kame picture kame · Oct 26, 2010 · Viewed 49.3k times · Source

How to show an easy latex-formula in python? Maybe numpy is the right choice?

EDIT:

I have python code like:

a = '\frac{a}{b}'

and want to print this in a graphical output (like matplotlib).

Answer

Bernardo Kyotoku picture Bernardo Kyotoku · Oct 27, 2010

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()