def latex_to_png_mpl(s, wrap):
try:
from matplotlib import mathtext
from pyparsing import ParseFatalException
except ImportError:
return None
# mpl mathtext doesn't support display math, force inline
s = s.replace('$$', '$')
if wrap:
s = u'${0}$'.format(s)
try:
mt = mathtext.MathTextParser('bitmap')
f = BytesIO()
mt.to_png(f, s, fontsize=12)
return f.getvalue()
except (ValueError, RuntimeError, ParseFatalException):
return None
评论列表
文章目录