summaryrefslogtreecommitdiff
path: root/sphinx/ext/pngmath.py
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2008-11-20 21:38:21 +0200
committerPauli Virtanen <pav@iki.fi>2008-11-20 21:38:21 +0200
commit6be9f22ecfc53fc3f4a19f4e82d49686cbfd0975 (patch)
tree05cfd3ac66b60fffb3adaf7fec94f230b098f0a3 /sphinx/ext/pngmath.py
parent331f625f91e1a079424e18779e7d26e120c9e426 (diff)
downloadsphinx-git-6be9f22ecfc53fc3f4a19f4e82d49686cbfd0975.tar.gz
sphinx.ext.pngmath: make Latex errors non-fatal for HTML output
Diffstat (limited to 'sphinx/ext/pngmath.py')
-rw-r--r--sphinx/ext/pngmath.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py
index aa0d0c2e6..74f823ac7 100644
--- a/sphinx/ext/pngmath.py
+++ b/sphinx/ext/pngmath.py
@@ -177,8 +177,29 @@ def cleanup_tempdir(app, exc):
except Exception:
pass
+def _html_error(latex, message):
+ html = """
+<div class="system-message">
+ <p class="system-message-title">System Message: WARNING/2</p>
+ <p>Latex error in a math directive</p>
+ <pre class="literal-block">
+ %s
+ </pre>
+ <pre class="literal-block">
+ %s
+ </pre>
+ </p>
+</div>
+""" % (latex, message)
+ print "WARNING:", message
+ return html
+
def html_visit_math(self, node):
- fname, depth = render_math(self, '$'+node['latex']+'$')
+ try:
+ fname, depth = render_math(self, '$'+node['latex']+'$')
+ except MathExtError, exc:
+ self.body.append(_html_error(node['latex'], 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 ''))
@@ -189,7 +210,11 @@ def html_visit_displaymath(self, node):
latex = node['latex']
else:
latex = wrap_displaymath(node['latex'], None)
- fname, depth = render_math(self, latex)
+ try:
+ fname, depth = render_math(self, latex)
+ except MathExtError, exc:
+ self.body.append(_html_error(node['latex'], exc))
+ raise nodes.SkipNode
self.body.append(self.starttag(node, 'div', CLASS='math'))
self.body.append('<p>')
if node['number']: