Skip to content

Commit

Permalink
Merge pull request #12150 from anntzer/stackrel
Browse files Browse the repository at this point in the history
Deprecate \stackrel.
  • Loading branch information
jklymak committed Feb 22, 2019
2 parents cf6f1af + df56b7e commit 977f415
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
11 changes: 11 additions & 0 deletions doc/api/next_api_changes/2018-08-19-AL-deprecations.rst
@@ -0,0 +1,11 @@
Deprecations
````````````

The ``\stackrel`` mathtext command is deprecated (it behaved differently
from LaTeX's ``\stackrel``. To stack two mathtext expressions, use
``\genfrac{left-delim}{right-delim}{fraction-bar-thickness}{}{top}{bottom}``.

Undeprecations
``````````````

The ``obj_type`` kwarg to the ``cbook.deprecated`` decorator is undeprecated.
2 changes: 1 addition & 1 deletion examples/text_labels_and_annotations/mathtext_examples.py
Expand Up @@ -34,7 +34,7 @@
r"\alpha_{i+1}^j = {\rm sin}(2\pi f_j t_i) e^{-5 t_i/\tau},\ "
r"\ldots$",

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

3: r"$\sqrt{2},\ \sqrt[3]{x},\ \ldots$",
Expand Down
37 changes: 19 additions & 18 deletions lib/matplotlib/cbook/deprecation.py
Expand Up @@ -86,18 +86,18 @@ def warn_deprecated(
If True, uses a PendingDeprecationWarning instead of a
DeprecationWarning. Cannot be used together with *removal*.
removal : str, optional
The expected removal version. With the default (an empty string), a
removal version is automatically computed from *since*. Set to other
Falsy values to not schedule a removal date. Cannot be used together
with *pending*.
obj_type : str, optional
The object type being deprecated.
addendum : str, optional
Additional text appended directly to the final message.
removal : str, optional
The expected removal version. With the default (an empty string), a
removal version is automatically computed from *since*. Set to other
Falsy values to not schedule a removal date. Cannot be used together
with *pending*.
Examples
--------
Expand Down Expand Up @@ -157,15 +157,19 @@ def new_function():
If True, uses a PendingDeprecationWarning instead of a
DeprecationWarning. Cannot be used together with *removal*.
obj_type : str, optional
The object type being deprecated; by default, 'function' if decorating
a function and 'class' if decorating a class.
addendum : str, optional
Additional text appended directly to the final message.
removal : str, optional
The expected removal version. With the default (an empty string), a
removal version is automatically computed from *since*. Set to other
Falsy values to not schedule a removal date. Cannot be used together
with *pending*.
addendum : str, optional
Additional text appended directly to the final message.
Examples
--------
Expand All @@ -176,16 +180,12 @@ def the_function_to_deprecate():
pass
"""

if obj_type is not None:
warn_deprecated(
"3.0", message="Passing 'obj_type' to the 'deprecated' decorator "
"has no effect, and is deprecated since Matplotlib %(since)s; "
"support for it will be removed %(removal)s.")

def deprecate(obj, message=message, name=name, alternative=alternative,
pending=pending, addendum=addendum):
pending=pending, obj_type=obj_type, addendum=addendum):

if isinstance(obj, type):
obj_type = "class"
if obj_type is None:
obj_type = "class"
func = obj.__init__
name = name or obj.__name__
old_doc = obj.__doc__
Expand Down Expand Up @@ -225,7 +225,8 @@ def finalize(_, new_doc):
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc)

else:
obj_type = "function"
if obj_type is None:
obj_type = "function"
func = obj
name = name or obj.__name__
old_doc = func.__doc__
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/mathtext.py
Expand Up @@ -3183,6 +3183,8 @@ def dfrac(self, s, loc, toks):
return self._genfrac('', '', thickness,
self._math_style_dict['displaystyle'], num, den)

@cbook.deprecated("3.1", obj_type="mathtext command",
alternative=r"\genfrac")
def stackrel(self, s, loc, toks):
assert len(toks) == 1
assert len(toks[0]) == 2
Expand Down
7 changes: 4 additions & 3 deletions tutorials/text/mathtext.py
Expand Up @@ -80,15 +80,16 @@
-----------------------------------------
Fractions, binomials, and stacked numbers can be created with the
``\frac{}{}``, ``\binom{}{}`` and ``\stackrel{}{}`` commands, respectively::
``\frac{}{}``, ``\binom{}{}`` and ``\genfrac{}{}{}{}{}{}`` commands,
respectively::
r'$\frac{3}{4} \binom{3}{4} \stackrel{3}{4}$'
r'$\frac{3}{4} \binom{3}{4} \genfrac{}{}{0}{}{3}{4}$'
produces
.. math::
\frac{3}{4} \binom{3}{4} \stackrel{3}{4}
\frac{3}{4} \binom{3}{4} \stackrel{}{}{0}{}{3}{4}
Fractions can be arbitrarily nested::
Expand Down

0 comments on commit 977f415

Please sign in to comment.