##// END OF EJS Templates
Backport PR #9203: Latextools: Make latex_to_png_mpl not fail on errors...
Min RK -
Show More
@@ -97,18 +97,22 def latex_to_png(s, encode=False, backend=None, wrap=False):
97 97 def latex_to_png_mpl(s, wrap):
98 98 try:
99 99 from matplotlib import mathtext
100 from pyparsing import ParseFatalException
100 101 except ImportError:
101 102 return None
102
103
103 104 # mpl mathtext doesn't support display math, force inline
104 105 s = s.replace('$$', '$')
105 106 if wrap:
106 107 s = u'${0}$'.format(s)
107
108 mt = mathtext.MathTextParser('bitmap')
109 f = BytesIO()
110 mt.to_png(f, s, fontsize=12)
111 return f.getvalue()
108
109 try:
110 mt = mathtext.MathTextParser('bitmap')
111 f = BytesIO()
112 mt.to_png(f, s, fontsize=12)
113 return f.getvalue()
114 except (ValueError, RuntimeError, ParseFatalException):
115 return None
112 116
113 117
114 118 def latex_to_png_dvipng(s, wrap):
@@ -138,6 +142,8 def latex_to_png_dvipng(s, wrap):
138 142
139 143 with open(outfile, "rb") as f:
140 144 return f.read()
145 except subprocess.CalledProcessError:
146 return None
141 147 finally:
142 148 shutil.rmtree(workdir)
143 149
General Comments 0
You need to be logged in to leave comments. Login now