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

Skip to content

Commit 58c53bd

Browse files
committed
Warn when a math expression can not be rendered, rather than hard-failing.
svn path=/trunk/matplotlib/; revision=5572
1 parent 4554032 commit 58c53bd

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

doc/sphinxext/mathpng.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from docutils.parsers.rst import directives
99
from docutils.writers.html4css1 import HTMLTranslator
1010
from sphinx.latexwriter import LaTeXTranslator
11+
import warnings
1112

1213
# Define LaTeX math node:
1314
class latex_math(nodes.General, nodes.Element):
@@ -116,7 +117,11 @@ def latex2png(latex, filename, fontset='cm'):
116117
return
117118
orig_fontset = rcParams['mathtext.fontset']
118119
rcParams['mathtext.fontset'] = fontset
119-
mathtext_parser.to_png(filename, "$%s$" % latex, dpi=120)
120+
try:
121+
mathtext_parser.to_png(filename, "$%s$" % latex, dpi=120)
122+
except:
123+
warnings.warn("Could not render math expression $%s$" % latex,
124+
warnings.Warning)
120125
rcParams['mathtext.fontset'] = orig_fontset
121126

122127
# LaTeX to HTML translation stuff:

0 commit comments

Comments
 (0)