Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 133adb1

Browse files
committed
Bugfix for re-generating math images
svn path=/trunk/matplotlib/; revision=5581
1 parent f8d4a23 commit 133adb1

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

doc/sphinxext/mathpng.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,25 @@ def latex2png(latex, name):
114114
# This uses mathtext to render the expression
115115
def latex2png(latex, filename, fontset='cm'):
116116
latex = "$%s$" % latex
117-
if os.path.exists(filename):
118-
return mathtext_parser.get_depth(latex, dpi=120)
119117
orig_fontset = rcParams['mathtext.fontset']
120118
rcParams['mathtext.fontset'] = fontset
121-
try:
122-
depth = mathtext_parser.to_png(filename, latex, dpi=120)
123-
except:
124-
warnings.warn("Could not render math expression %s" % latex,
125-
Warning)
126-
depth = 0
119+
if os.path.exists(filename):
120+
depth = mathtext_parser.get_depth(latex, dpi=120)
121+
else:
122+
print latex.encode("ascii", "backslashreplace")
123+
try:
124+
depth = mathtext_parser.to_png(filename, latex, dpi=120)
125+
except:
126+
warnings.warn("Could not render math expression %s" % latex,
127+
Warning)
128+
depth = 0
127129
rcParams['mathtext.fontset'] = orig_fontset
128130
return depth
129131

130132
# LaTeX to HTML translation stuff:
131133
def latex2html(node, source):
132134
inline = isinstance(node.parent, nodes.TextElement)
133135
latex = node['latex']
134-
print latex.encode("ascii", "backslashreplace")
135136
name = 'math-%s' % md5(latex).hexdigest()[-10:]
136137
dest = '_static/%s.png' % name
137138
depth = latex2png(latex, dest, node['fontset'])

0 commit comments

Comments
 (0)