Show More
@@ -97,6 +97,7 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 | |||
@@ -105,10 +106,13 def latex_to_png_mpl(s, wrap): | |||||
105 | if wrap: |
|
106 | if wrap: | |
106 | s = u'${0}$'.format(s) |
|
107 | s = u'${0}$'.format(s) | |
107 |
|
108 | |||
|
109 | try: | |||
108 | mt = mathtext.MathTextParser('bitmap') |
|
110 | mt = mathtext.MathTextParser('bitmap') | |
109 | f = BytesIO() |
|
111 | f = BytesIO() | |
110 | mt.to_png(f, s, fontsize=12) |
|
112 | mt.to_png(f, s, fontsize=12) | |
111 | return f.getvalue() |
|
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