From 60952925608a36740aa14cc876aa22b733f23eca Mon Sep 17 00:00:00 2001 From: Daniel Knuettel Date: Sat, 3 Feb 2018 18:31:47 +0100 Subject: [PATCH] fixed a bug with wrong LaTeX input --- mathbot/rendering.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mathbot/rendering.py b/mathbot/rendering.py index a001d78..1c721a0 100644 --- a/mathbot/rendering.py +++ b/mathbot/rendering.py @@ -20,21 +20,34 @@ from io import BytesIO import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt +import importlib def get_png(tex): + importlib.reload(plt) buf = BytesIO() - plt.text(0, 0.6, r"$%s$" % tex, fontsize = 50) - fig = plt.gca() - fig.axes.get_xaxis().set_visible(False) - fig.axes.get_yaxis().set_visible(False) + exc = None - plt.savefig(buf) + try: + plt.subplot() - buf.seek(0) + plt.text(0, 0.6, r"$%s$" % tex, fontsize = 50) + fig = plt.gca() + fig.axes.get_xaxis().set_visible(False) + fig.axes.get_yaxis().set_visible(False) - plt.clf() + plt.savefig(buf) + + buf.seek(0) + + except Exception as e: + exc = e + finally: + plt.clf() + + if(exc): + raise exc return buf