From 9649d8365560be32d82871f4d86528d6386c3d48 Mon Sep 17 00:00:00 2001 From: Aitik Gupta Date: Thu, 11 Feb 2021 14:35:58 +0530 Subject: [PATCH 1/4] Add overset/underset whatsnew entry --- doc/users/next_whats_new/mathtext.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 doc/users/next_whats_new/mathtext.rst diff --git a/doc/users/next_whats_new/mathtext.rst b/doc/users/next_whats_new/mathtext.rst new file mode 100644 index 000000000000..2ebf711547c3 --- /dev/null +++ b/doc/users/next_whats_new/mathtext.rst @@ -0,0 +1,14 @@ +``matplotlib.mathtext`` now supports *overset* and *underset* LaTeX symbols +--------------------------------------------------------------------------- + +`.mathtext`, the default TeX layout engine which is shipped along with +Matplotlib now supports symbols like *overset* and *underset*. + +The structure which should be followed: "\overset{body}{annotation}" or +"\underset{body}{annotation}", where *body* would be the text "above" or +"below" the *annotation* - the baseline character. + +.. plot:: + + math_expr = r"$ x \overset{f}{\rightarrow} y \underset{f}{\leftarrow} z $" + plt.text(0.4, 0.5, math_expr, usetex=False) From 2913f08e1fe49d35a253fd81efd4642918bf5f7f Mon Sep 17 00:00:00 2001 From: Aitik Gupta Date: Thu, 11 Feb 2021 22:02:19 +0530 Subject: [PATCH 2/4] Exchange variable names --- lib/matplotlib/_mathtext.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 44a87a5a4a3d..6f0e47b239e6 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -2859,32 +2859,32 @@ def binom(self, s, loc, toks): return self._genfrac('(', ')', 0.0, self._MathStyle.TEXTSTYLE, num, den) - def _genset(self, state, body, annotation, overunder): + def _genset(self, state, annotation, body, overunder): thickness = state.font_output.get_underline_thickness( state.font, state.fontsize, state.dpi) - body.shrink() + annotation.shrink() - cbody = HCentered([body]) cannotation = HCentered([annotation]) - width = max(cbody.width, cannotation.width) - cbody.hpack(width, 'exactly') + cbody = HCentered([body]) + width = max(cannotation.width, cbody.width) cannotation.hpack(width, 'exactly') + cbody.hpack(width, 'exactly') vgap = thickness * 3 if overunder == "under": - vlist = Vlist([cannotation, # annotation - Vbox(0, vgap), # space - cbody # body + vlist = Vlist([cbody, # body + Vbox(0, vgap), # space + cannotation # annotation ]) - # Shift so the annotation sits in the same vertical position - shift_amount = cannotation.depth + cbody.height + vgap + # Shift so the body sits in the same vertical position + shift_amount = cbody.depth + cannotation.height + vgap vlist.shift_amount = shift_amount else: - vlist = Vlist([cbody, # body - Vbox(0, vgap), # space - cannotation # annotation + vlist = Vlist([cannotation, # annotation + Vbox(0, vgap), # space + cbody # body ]) # To add horizontal gap between symbols: wrap the Vlist into @@ -2956,18 +2956,18 @@ def overset(self, s, loc, toks): assert len(toks[0]) == 2 state = self.get_state() - body, annotation = toks[0] + annotation, body = toks[0] - return self._genset(state, body, annotation, overunder="over") + return self._genset(state, annotation, body, overunder="over") def underset(self, s, loc, toks): assert len(toks) == 1 assert len(toks[0]) == 2 state = self.get_state() - body, annotation = toks[0] + annotation, body = toks[0] - return self._genset(state, body, annotation, overunder="under") + return self._genset(state, annotation, body, overunder="under") def _auto_sized_delimiter(self, front, middle, back): state = self.get_state() From d891481ca8160e645ee8a472bec5f012d7783142 Mon Sep 17 00:00:00 2001 From: Aitik Gupta Date: Thu, 11 Feb 2021 22:03:08 +0530 Subject: [PATCH 3/4] Simplify whatsnew entry --- doc/users/next_whats_new/mathtext.rst | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/doc/users/next_whats_new/mathtext.rst b/doc/users/next_whats_new/mathtext.rst index 2ebf711547c3..1cacb9524b65 100644 --- a/doc/users/next_whats_new/mathtext.rst +++ b/doc/users/next_whats_new/mathtext.rst @@ -1,12 +1,9 @@ ``matplotlib.mathtext`` now supports *overset* and *underset* LaTeX symbols --------------------------------------------------------------------------- -`.mathtext`, the default TeX layout engine which is shipped along with -Matplotlib now supports symbols like *overset* and *underset*. - -The structure which should be followed: "\overset{body}{annotation}" or -"\underset{body}{annotation}", where *body* would be the text "above" or -"below" the *annotation* - the baseline character. +`.mathtext` now supports *overset* and *underset*, called as +``\overset{body}{annotation}`` or ``\underset{body}{annotation}``, where +*annotation* is the text "above" or "below" the *body*. .. plot:: From c82cadd2b9a4d10fe200b2019acc2e5017e57695 Mon Sep 17 00:00:00 2001 From: Aitik Gupta Date: Thu, 11 Feb 2021 22:32:09 +0530 Subject: [PATCH 4/4] One more exchange --- doc/users/next_whats_new/mathtext.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/users/next_whats_new/mathtext.rst b/doc/users/next_whats_new/mathtext.rst index 1cacb9524b65..d864f975c48c 100644 --- a/doc/users/next_whats_new/mathtext.rst +++ b/doc/users/next_whats_new/mathtext.rst @@ -2,7 +2,7 @@ --------------------------------------------------------------------------- `.mathtext` now supports *overset* and *underset*, called as -``\overset{body}{annotation}`` or ``\underset{body}{annotation}``, where +``\overset{annotation}{body}`` or ``\underset{annotation}{body}``, where *annotation* is the text "above" or "below" the *body*. .. plot::