##// 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 def latex_to_png_mpl(s, wrap):
97 def latex_to_png_mpl(s, wrap):
98 try:
98 try:
99 from matplotlib import mathtext
99 from matplotlib import mathtext
100 from pyparsing import ParseFatalException
100 except ImportError:
101 except ImportError:
101 return None
102 return None
102
103
103 # mpl mathtext doesn't support display math, force inline
104 # mpl mathtext doesn't support display math, force inline
104 s = s.replace('$$', '$')
105 s = s.replace('$$', '$')
105 if wrap:
106 if wrap:
106 s = u'${0}$'.format(s)
107 s = u'${0}$'.format(s)
107
108
108 mt = mathtext.MathTextParser('bitmap')
109 try:
109 f = BytesIO()
110 mt = mathtext.MathTextParser('bitmap')
110 mt.to_png(f, s, fontsize=12)
111 f = BytesIO()
111 return f.getvalue()
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 def latex_to_png_dvipng(s, wrap):
118 def latex_to_png_dvipng(s, wrap):
@@ -138,6 +142,8 def latex_to_png_dvipng(s, wrap):
138
142
139 with open(outfile, "rb") as f:
143 with open(outfile, "rb") as f:
140 return f.read()
144 return f.read()
145 except subprocess.CalledProcessError:
146 return None
141 finally:
147 finally:
142 shutil.rmtree(workdir)
148 shutil.rmtree(workdir)
143
149
General Comments 0
You need to be logged in to leave comments. Login now