Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edc35fd

Browse filesBrowse files
authored
Merge pull request #13781 from meeseeksmachine/auto-backport-of-pr-13777-on-v3.1.x
Backport PR #13777 on branch v3.1.x (Use class-based directive for mathmpl sphinxext.)
2 parents 2a1042c + 91a6136 commit edc35fd
Copy full SHA for edc35fd

File tree

Expand file treeCollapse file tree

2 files changed

+26
-15
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-15
lines changed
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
Deprecations
22
````````````
33

4-
The ``matplotlib.sphinxext.plot_directive`` interface has changed from
5-
the (Sphinx-)deprecated function-based interface to a class-based interface.
6-
This should not affect end users, but the
7-
``matplotlib.sphinxext.plot_directive.plot_directive`` function is now
4+
The ``matplotlib.sphinxext.mathmpl`` and
5+
``matplotlib.sphinxext.plot_directive`` interfaces have changed from the
6+
(Sphinx-)deprecated function-based interface to a class-based interface. This
7+
should not affect end users, but the
8+
``matplotlib.sphinxext.mathmpl.math_directive`` and
9+
``matplotlib.sphinxext.plot_directive.plot_directive`` functions are now
810
deprecated.

‎lib/matplotlib/sphinxext/mathmpl.py

Copy file name to clipboardExpand all lines: lib/matplotlib/sphinxext/mathmpl.py
+20-11Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55
from docutils import nodes
6-
from docutils.parsers.rst import directives
6+
from docutils.parsers.rst import Directive, directives
77
import sphinx
88

99
from matplotlib import rcParams
@@ -22,9 +22,6 @@ def fontset_choice(arg):
2222
return directives.choice(arg, ['cm', 'stix', 'stixsans'])
2323

2424

25-
options_spec = {'fontset': fontset_choice}
26-
27-
2825
def math_role(role, rawtext, text, lineno, inliner,
2926
options={}, content=[]):
3027
i = rawtext.find('`')
@@ -33,11 +30,10 @@ def math_role(role, rawtext, text, lineno, inliner,
3330
node['latex'] = latex
3431
node['fontset'] = options.get('fontset', 'cm')
3532
return [node], []
33+
math_role.options = {'fontset': fontset_choice}
3634

3735

38-
math_role.options = options_spec
39-
40-
36+
@cbook.deprecated("3.1", alternative="MathDirective")
4137
def math_directive(name, arguments, options, content, lineno,
4238
content_offset, block_text, state, state_machine):
4339
latex = ''.join(content)
@@ -47,6 +43,21 @@ def math_directive(name, arguments, options, content, lineno,
4743
return [node]
4844

4945

46+
class MathDirective(Directive):
47+
has_content = True
48+
required_arguments = 0
49+
optional_arguments = 0
50+
final_argument_whitespace = False
51+
option_spec = {'fontset': fontset_choice}
52+
53+
def run(self):
54+
latex = ''.join(self.content)
55+
node = latex_math(self.block_text)
56+
node['latex'] = latex
57+
node['fontset'] = self.options.get('fontset', 'cm')
58+
return [node]
59+
60+
5061
# This uses mathtext to render the expression
5162
def latex2png(latex, filename, fontset='cm'):
5263
latex = "$%s$" % latex
@@ -121,12 +132,10 @@ def depart_latex_math_latex(self, node):
121132
html=(visit_latex_math_html, depart_latex_math_html),
122133
latex=(visit_latex_math_latex, depart_latex_math_latex))
123134
app.add_role('mathmpl', math_role)
124-
app.add_directive('mathmpl', math_directive,
125-
True, (0, 0, 0), **options_spec)
135+
app.add_directive('mathmpl', MathDirective)
126136
if sphinx.version_info < (1, 8):
127137
app.add_role('math', math_role)
128-
app.add_directive('math', math_directive,
129-
True, (0, 0, 0), **options_spec)
138+
app.add_directive('math', MathDirective)
130139

131140
metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
132141
return metadata

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.