@@ -114,24 +114,25 @@ def latex2png(latex, name):
114114# This uses mathtext to render the expression
115115def 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:
131133def 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