From 5b78b6fcfb485dd7abeed8603afcd41f0b4c9a9a Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 11 Feb 2021 19:18:14 +0100 Subject: [PATCH] Fully fold overset/underset into _genset. No need to repeat the tokens expansion twice, and it seems reasonable enough to check the string itself instead of inventing a separate parameter just to pass the information of whether an overset or an underset is being handled. --- lib/matplotlib/_mathtext.py | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 6f0e47b239e6..2d9df8f34be4 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -2859,12 +2859,13 @@ def binom(self, s, loc, toks): return self._genfrac('(', ')', 0.0, self._MathStyle.TEXTSTYLE, num, den) - def _genset(self, state, annotation, body, overunder): + def _genset(self, s, loc, toks): + (annotation, body), = toks + state = self.get_state() thickness = state.font_output.get_underline_thickness( state.font, state.fontsize, state.dpi) annotation.shrink() - cannotation = HCentered([annotation]) cbody = HCentered([body]) width = max(cannotation.width, cbody.width) @@ -2872,16 +2873,14 @@ def _genset(self, state, annotation, body, overunder): cbody.hpack(width, 'exactly') vgap = thickness * 3 - if overunder == "under": + if s[loc + 1] == "u": # \underset vlist = Vlist([cbody, # body Vbox(0, vgap), # space cannotation # annotation ]) # Shift so the body sits in the same vertical position - shift_amount = cbody.depth + cannotation.height + vgap - - vlist.shift_amount = shift_amount - else: + vlist.shift_amount = cbody.depth + cannotation.height + vgap + else: # \overset vlist = Vlist([cannotation, # annotation Vbox(0, vgap), # space cbody # body @@ -2891,6 +2890,8 @@ def _genset(self, state, annotation, body, overunder): # an Hlist and extend it with an Hbox(0, horizontal_gap) return vlist + overset = underset = _genset + def sqrt(self, s, loc, toks): (root, body), = toks state = self.get_state() @@ -2951,24 +2952,6 @@ def overline(self, s, loc, toks): hlist = Hlist([rightside]) return [hlist] - def overset(self, s, loc, toks): - assert len(toks) == 1 - assert len(toks[0]) == 2 - - state = self.get_state() - annotation, body = toks[0] - - 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() - annotation, body = toks[0] - - return self._genset(state, annotation, body, overunder="under") - def _auto_sized_delimiter(self, front, middle, back): state = self.get_state() if len(middle):