Skip to content

Commit 992a6f5

Browse files
committed
Deprecate \stackrel.
Mathtext's \stackrel{a}{b} behaves subtly differently from latex's \stackrel{a}{b}: mathtext makes `a` and `b` equal-sized whereas latex makes `a` smaller than `b` (`a` is an "annotation" over `b`). Given that we can already stack expressions using the (admittedly less practical, but standard) \genfrac, just deprecate \stackrel instead of maintaining our own latex-like dialect. Also undeprecate passing obj_type to the cbook.deprecated decorator(!), given that this PR has a good reason to use it... and while we're at it, reorder the kwargs docs for cbook.deprecated and cbook.warn_deprecated to match the order in the signature.
1 parent 7ff8a66 commit 992a6f5

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Deprecations
2+
````````````
3+
4+
The ``\stackrel`` mathtext command is deprecated (it behaved differently
5+
from LaTeX's ``\stackrel``. To stack two mathtext expressions, use
6+
``\genfrac{left-delim}{right-delim}{fraction-bar-thickness}{}{top}{bottom}``.
7+
8+
Undeprecations
9+
``````````````
10+
11+
The ``obj_type`` kwarg to the ``cbook.deprecated`` decorator is undeprecated.

examples/text_labels_and_annotations/mathtext_examples.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
r"\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau},\ "
3535
r"\ldots$",
3636

37-
2: r"$\frac{3}{4},\ \binom{3}{4},\ \stackrel{3}{4},\ "
37+
2: r"$\frac{3}{4},\ \binom{3}{4},\ \genfrac{}{}{0}{}{3}{4},\ "
3838
r"\left(\frac{5 - \frac{1}{x}}{4}\right),\ \ldots$",
3939

4040
3: r"$\sqrt{2},\ \sqrt[3]{x},\ \ldots$",

lib/matplotlib/cbook/deprecation.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ def warn_deprecated(
8686
If True, uses a PendingDeprecationWarning instead of a
8787
DeprecationWarning. Cannot be used together with *removal*.
8888
89-
removal : str, optional
90-
The expected removal version. With the default (an empty string), a
91-
removal version is automatically computed from *since*. Set to other
92-
Falsy values to not schedule a removal date. Cannot be used together
93-
with *pending*.
94-
9589
obj_type : str, optional
9690
The object type being deprecated.
9791
9892
addendum : str, optional
9993
Additional text appended directly to the final message.
10094
95+
removal : str, optional
96+
The expected removal version. With the default (an empty string), a
97+
removal version is automatically computed from *since*. Set to other
98+
Falsy values to not schedule a removal date. Cannot be used together
99+
with *pending*.
100+
101101
Examples
102102
--------
103103
@@ -157,15 +157,19 @@ def new_function():
157157
If True, uses a PendingDeprecationWarning instead of a
158158
DeprecationWarning. Cannot be used together with *removal*.
159159
160+
obj_type : str, optional
161+
The object type being deprecated; by default, 'function' if decorating
162+
a function and 'class' if decorating a class.
163+
164+
addendum : str, optional
165+
Additional text appended directly to the final message.
166+
160167
removal : str, optional
161168
The expected removal version. With the default (an empty string), a
162169
removal version is automatically computed from *since*. Set to other
163170
Falsy values to not schedule a removal date. Cannot be used together
164171
with *pending*.
165172
166-
addendum : str, optional
167-
Additional text appended directly to the final message.
168-
169173
Examples
170174
--------
171175
@@ -176,16 +180,12 @@ def the_function_to_deprecate():
176180
pass
177181
"""
178182

179-
if obj_type is not None:
180-
warn_deprecated(
181-
"3.0", message="Passing 'obj_type' to the 'deprecated' decorator "
182-
"has no effect, and is deprecated since Matplotlib %(since)s; "
183-
"support for it will be removed %(removal)s.")
184-
185183
def deprecate(obj, message=message, name=name, alternative=alternative,
186184
pending=pending, addendum=addendum):
185+
187186
if isinstance(obj, type):
188-
obj_type = "class"
187+
if obj_type is None:
188+
obj_type = "class"
189189
func = obj.__init__
190190
name = name or obj.__name__
191191
old_doc = obj.__doc__
@@ -225,7 +225,8 @@ def finalize(_, new_doc):
225225
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc)
226226

227227
else:
228-
obj_type = "function"
228+
if obj_type is None:
229+
obj_type = "function"
229230
func = obj
230231
name = name or obj.__name__
231232
old_doc = func.__doc__

lib/matplotlib/mathtext.py

+2
Original file line numberDiff line numberDiff line change
@@ -3183,6 +3183,8 @@ def dfrac(self, s, loc, toks):
31833183
return self._genfrac('', '', thickness,
31843184
self._math_style_dict['displaystyle'], num, den)
31853185

3186+
@cbook.deprecated("3.1", obj_type="mathtext command",
3187+
alternative=r"\genfrac")
31863188
def stackrel(self, s, loc, toks):
31873189
assert len(toks) == 1
31883190
assert len(toks[0]) == 2

tutorials/text/mathtext.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@
8080
-----------------------------------------
8181
8282
Fractions, binomials, and stacked numbers can be created with the
83-
``\frac{}{}``, ``\binom{}{}`` and ``\stackrel{}{}`` commands, respectively::
83+
``\frac{}{}``, ``\binom{}{}`` and ``\genfrac{}{}{}{}{}{}`` commands,
84+
respectively::
8485
85-
r'$\frac{3}{4} \binom{3}{4} \stackrel{3}{4}$'
86+
r'$\frac{3}{4} \binom{3}{4} \genfrac{}{}{0}{}{3}{4}$'
8687
8788
produces
8889
8990
.. math::
9091
91-
\frac{3}{4} \binom{3}{4} \stackrel{3}{4}
92+
\frac{3}{4} \binom{3}{4} \stackrel{}{}{0}{}{3}{4}
9293
9394
Fractions can be arbitrarily nested::
9495

0 commit comments

Comments
 (0)