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