Georg Brandl avatar Georg Brandl committed e09eadf

Don't call LaTeX or dvipng over and over again if it was not
found once, and use text-only latex as a substitute in that case.

Comments (0)

Files changed (2)

 Release 0.5.2 (in development)
 ==============================
 
+* Don't call LaTeX or dvipng over and over again if it was not
+  found once, and use text-only latex as a substitute in that case.
+
 * Fix problems with footnotes in the LaTeX output.
 
 * Prevent double hyphens becoming en-dashes in literal code in

sphinx/ext/pngmath.py

         depth = read_png_depth(outfn)
         return relfn, depth
 
+    # if latex or dvipng has failed once, don't bother to try again
+    if hasattr(self.builder, '_mathpng_warned_latex') or \
+       hasattr(self.builder, '_mathpng_warned_dvipng'):
+        return None, None
+
     latex = DOC_HEAD + self.builder.config.pngmath_latex_preamble
     latex += (use_preview and DOC_BODY_PREVIEW or DOC_BODY) % math
     if isinstance(latex, unicode):
         except OSError, err:
             if err.errno != 2:   # No such file or directory
                 raise
-            if not hasattr(self.builder, '_mathpng_warned_latex'):
-                self.builder.warn('LaTeX command %r cannot be run (needed for math '
-                                  'display), check the pngmath_latex setting' %
-                                  self.builder.config.pngmath_latex)
-                self.builder._mathpng_warned_latex = True
-            return relfn, None
+            self.builder.warn('LaTeX command %r cannot be run (needed for math '
+                              'display), check the pngmath_latex setting' %
+                              self.builder.config.pngmath_latex)
+            self.builder._mathpng_warned_latex = True
+            return None, None
     finally:
         chdir(curdir)
 
     except OSError, err:
         if err.errno != 2:   # No such file or directory
             raise
-        if not hasattr(self.builder, '_mathpng_warned_dvipng'):
-            self.builder.warn('dvipng command %r cannot be run (needed for math '
-                              'display), check the pngmath_dvipng setting' %
-                              self.builder.config.pngmath_dvipng)
-            self.builder._mathpng_warned_dvipng = True
-        return relfn, None
+        self.builder.warn('dvipng command %r cannot be run (needed for math '
+                          'display), check the pngmath_dvipng setting' %
+                          self.builder.config.pngmath_dvipng)
+        self.builder._mathpng_warned_dvipng = True
+        return None, None
     stdout, stderr = p.communicate()
     if p.returncode != 0:
         raise MathExtError('dvipng exited with error:\n[stderr]\n%s\n[stdout]\n%s'
         sm.walkabout(self)
         self.builder.warn('display latex %r: ' % node['latex'] + str(exc))
         raise nodes.SkipNode
-    self.body.append('<img class="math" src="%s" alt="%s" %s/>' %
-                     (fname, self.encode(node['latex']).strip(),
-                      depth and 'style="vertical-align: %dpx" ' % (-depth) or ''))
+    if fname is None:
+        # something failed -- use text-only as a bad substitute
+        self.body.append('<span class="math">%s</span>' %
+                         self.encode(node['latex']).strip())
+    else:
+        self.body.append(
+            '<img class="math" src="%s" alt="%s" %s/>' %
+            (fname, self.encode(node['latex']).strip(),
+             depth and 'style="vertical-align: %dpx" ' % (-depth) or ''))
     raise nodes.SkipNode
 
 def html_visit_displaymath(self, node):
     self.body.append('<p>')
     if node['number']:
         self.body.append('<span class="eqno">(%s)</span>' % node['number'])
-    self.body.append('<img src="%s" alt="%s" />\n</div>' %
-                     (fname, self.encode(node['latex']).strip()))
+    if fname is None:
+        # something failed -- use text-only as a bad substitute
+        self.body.append('<span class="math">%s</span>' %
+                         self.encode(node['latex']).strip())
+    else:
+        self.body.append('<img src="%s" alt="%s" />\n</div>' %
+                         (fname, self.encode(node['latex']).strip()))
     self.body.append('</p>')
     raise nodes.SkipNode
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.