diff --git a/IPython/lib/latextools.py b/IPython/lib/latextools.py index eb7c27b..88b0978 100644 --- a/IPython/lib/latextools.py +++ b/IPython/lib/latextools.py @@ -97,9 +97,10 @@ def latex_to_png(s, encode=False, backend=None, wrap=False): 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: @@ -110,7 +111,7 @@ def latex_to_png_mpl(s, wrap): f = BytesIO() mt.to_png(f, s, fontsize=12) return f.getvalue() - except: + except (ValueError, RuntimeError, ParseFatalException): return None @@ -141,7 +142,7 @@ def latex_to_png_dvipng(s, wrap): with open(outfile, "rb") as f: return f.read() - except: + except subprocess.CalledProcessError: return None finally: shutil.rmtree(workdir)