Skip to content

Commit 90b3bc1

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 13629a4 commit 90b3bc1

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
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

+17-19
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ def warn_deprecated(
8282
If True, uses a PendingDeprecationWarning instead of a
8383
DeprecationWarning. Cannot be used together with *removal*.
8484
85-
removal : str, optional
86-
The expected removal version. With the default (an empty string), a
87-
removal version is automatically computed from *since*. Set to other
88-
Falsy values to not schedule a removal date. Cannot be used together
89-
with *pending*.
90-
9185
obj_type : str, optional
9286
The object type being deprecated.
9387
9488
addendum : str, optional
9589
Additional text appended directly to the final message.
9690
91+
removal : str, optional
92+
The expected removal version. With the default (an empty string), a
93+
removal version is automatically computed from *since*. Set to other
94+
Falsy values to not schedule a removal date. Cannot be used together
95+
with *pending*.
96+
9797
Examples
9898
--------
9999
@@ -156,15 +156,19 @@ def new_function():
156156
If True, uses a PendingDeprecationWarning instead of a
157157
DeprecationWarning. Cannot be used together with *removal*.
158158
159+
obj_type : str, optional
160+
The object type being deprecated; by default, 'function' if decorating
161+
a function and 'class' if decorating a class.
162+
163+
addendum : str, optional
164+
Additional text appended directly to the final message.
165+
159166
removal : str, optional
160167
The expected removal version. With the default (an empty string), a
161168
removal version is automatically computed from *since*. Set to other
162169
Falsy values to not schedule a removal date. Cannot be used together
163170
with *pending*.
164171
165-
addendum : str, optional
166-
Additional text appended directly to the final message.
167-
168172
Examples
169173
--------
170174
@@ -175,16 +179,10 @@ def the_function_to_deprecate():
175179
pass
176180
"""
177181

178-
if obj_type is not None:
179-
warn_deprecated(
180-
"3.0", "Passing 'obj_type' to the 'deprecated' decorator has no "
181-
"effect, and is deprecated since Matplotlib %(since)s; support "
182-
"for it will be removed %(removal)s.")
183-
184182
def deprecate(obj, message=message, name=name, alternative=alternative,
185-
pending=pending, addendum=addendum):
183+
pending=pending, obj_type=obj_type, addendum=addendum):
186184
if isinstance(obj, type):
187-
obj_type = "class"
185+
obj_type = obj_type or "class"
188186
func = obj.__init__
189187
name = name or obj.__name__
190188
old_doc = obj.__doc__
@@ -195,7 +193,7 @@ def finalize(wrapper, new_doc):
195193
return obj
196194

197195
elif isinstance(obj, property):
198-
obj_type = "attribute"
196+
obj_type = obj_type or "attribute"
199197
func = None
200198
name = name or obj.fget.__name__
201199
old_doc = obj.__doc__
@@ -221,7 +219,7 @@ def finalize(_, new_doc):
221219
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc)
222220

223221
else:
224-
obj_type = "function"
222+
obj_type = obj_type or "function"
225223
func = obj
226224
name = name or obj.__name__
227225
old_doc = func.__doc__

lib/matplotlib/mathtext.py

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

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

tutorials/text/mathtext.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@
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, respectively::
8484
85-
r'$\frac{3}{4} \binom{3}{4} \stackrel{3}{4}$'
85+
r'$\frac{3}{4} \binom{3}{4} \genfrac{}{}{0}{}{3}{4}$'
8686
8787
produces
8888
8989
.. math::
9090
91-
\frac{3}{4} \binom{3}{4} \stackrel{3}{4}
91+
\frac{3}{4} \binom{3}{4} \genfrac{}{}{0}{}{3}{4}
9292
9393
Fractions can be arbitrarily nested::
9494

0 commit comments

Comments
 (0)