|
| 1 | +import hashlib |
1 | 2 | import os |
2 | 3 | import sys |
3 | | -from hashlib import md5 |
| 4 | +import warnings |
4 | 5 |
|
5 | 6 | from docutils import nodes |
6 | 7 | from docutils.parsers.rst import directives |
7 | | -import warnings |
| 8 | +import sphinx |
8 | 9 |
|
9 | 10 | from matplotlib import rcParams |
10 | 11 | from matplotlib.mathtext import MathTextParser |
@@ -61,7 +62,7 @@ def latex2png(latex, filename, fontset='cm'): |
61 | 62 | def latex2html(node, source): |
62 | 63 | inline = isinstance(node.parent, nodes.TextElement) |
63 | 64 | latex = node['latex'] |
64 | | - name = 'math-%s' % md5(latex.encode()).hexdigest()[-10:] |
| 65 | + name = 'math-%s' % hashlib.md5(latex.encode()).hexdigest()[-10:] |
65 | 66 |
|
66 | 67 | destdir = os.path.join(setup.app.builder.outdir, '_images', 'mathmpl') |
67 | 68 | if not os.path.exists(destdir): |
@@ -110,9 +111,13 @@ def depart_latex_math_latex(self, node): |
110 | 111 | app.add_node(latex_math, |
111 | 112 | html=(visit_latex_math_html, depart_latex_math_html), |
112 | 113 | latex=(visit_latex_math_latex, depart_latex_math_latex)) |
113 | | - app.add_role('math', math_role) |
114 | | - app.add_directive('math', math_directive, |
| 114 | + app.add_role('mathmpl', math_role) |
| 115 | + app.add_directive('mathmpl', math_directive, |
115 | 116 | True, (0, 0, 0), **options_spec) |
| 117 | + if sphinx.version_info < (1, 8): |
| 118 | + app.add_role('math', math_role) |
| 119 | + app.add_directive('math', math_directive, |
| 120 | + True, (0, 0, 0), **options_spec) |
116 | 121 |
|
117 | 122 | metadata = {'parallel_read_safe': True, 'parallel_write_safe': True} |
118 | 123 | return metadata |
0 commit comments