From 607cdcdd71572a53806d328b965e0c45ac6634dd 2016-02-02 00:48:23 From: Carlos Cordoba Date: 2016-02-02 00:48:23 Subject: [PATCH] Latextools: Make latex_to_png_mpl not fail on errors - Also make make both latex_to_foo functions to return None on failure. - This will help to solve the errors qtconsole is having to handle Latex. --- diff --git a/IPython/lib/latextools.py b/IPython/lib/latextools.py index 159b822..eb7c27b 100644 --- a/IPython/lib/latextools.py +++ b/IPython/lib/latextools.py @@ -104,11 +104,14 @@ def latex_to_png_mpl(s, wrap): s = s.replace('$$', '$') if wrap: s = u'${0}$'.format(s) - - mt = mathtext.MathTextParser('bitmap') - f = BytesIO() - mt.to_png(f, s, fontsize=12) - return f.getvalue() + + try: + mt = mathtext.MathTextParser('bitmap') + f = BytesIO() + mt.to_png(f, s, fontsize=12) + return f.getvalue() + except: + return None def latex_to_png_dvipng(s, wrap): @@ -138,6 +141,8 @@ def latex_to_png_dvipng(s, wrap): with open(outfile, "rb") as f: return f.read() + except: + return None finally: shutil.rmtree(workdir)