Skip to content

Commit aec7ec8

Browse files
authored
Merge pull request #19499 from anntzer/overunder
Fully fold overset/underset into _genset.
2 parents 303873f + 5b78b6f commit aec7ec8

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,29 +2813,28 @@ def binom(self, s, loc, toks):
28132813
return self._genfrac('(', ')', 0.0, self._MathStyle.TEXTSTYLE,
28142814
num, den)
28152815

2816-
def _genset(self, state, annotation, body, overunder):
2816+
def _genset(self, s, loc, toks):
2817+
(annotation, body), = toks
2818+
state = self.get_state()
28172819
thickness = state.font_output.get_underline_thickness(
28182820
state.font, state.fontsize, state.dpi)
28192821

28202822
annotation.shrink()
2821-
28222823
cannotation = HCentered([annotation])
28232824
cbody = HCentered([body])
28242825
width = max(cannotation.width, cbody.width)
28252826
cannotation.hpack(width, 'exactly')
28262827
cbody.hpack(width, 'exactly')
28272828

28282829
vgap = thickness * 3
2829-
if overunder == "under":
2830+
if s[loc + 1] == "u": # \underset
28302831
vlist = Vlist([cbody, # body
28312832
Vbox(0, vgap), # space
28322833
cannotation # annotation
28332834
])
28342835
# Shift so the body sits in the same vertical position
2835-
shift_amount = cbody.depth + cannotation.height + vgap
2836-
2837-
vlist.shift_amount = shift_amount
2838-
else:
2836+
vlist.shift_amount = cbody.depth + cannotation.height + vgap
2837+
else: # \overset
28392838
vlist = Vlist([cannotation, # annotation
28402839
Vbox(0, vgap), # space
28412840
cbody # body
@@ -2845,6 +2844,8 @@ def _genset(self, state, annotation, body, overunder):
28452844
# an Hlist and extend it with an Hbox(0, horizontal_gap)
28462845
return vlist
28472846

2847+
overset = underset = _genset
2848+
28482849
def sqrt(self, s, loc, toks):
28492850
(root, body), = toks
28502851
state = self.get_state()
@@ -2905,24 +2906,6 @@ def overline(self, s, loc, toks):
29052906
hlist = Hlist([rightside])
29062907
return [hlist]
29072908

2908-
def overset(self, s, loc, toks):
2909-
assert len(toks) == 1
2910-
assert len(toks[0]) == 2
2911-
2912-
state = self.get_state()
2913-
annotation, body = toks[0]
2914-
2915-
return self._genset(state, annotation, body, overunder="over")
2916-
2917-
def underset(self, s, loc, toks):
2918-
assert len(toks) == 1
2919-
assert len(toks[0]) == 2
2920-
2921-
state = self.get_state()
2922-
annotation, body = toks[0]
2923-
2924-
return self._genset(state, annotation, body, overunder="under")
2925-
29262909
def _auto_sized_delimiter(self, front, middle, back):
29272910
state = self.get_state()
29282911
if len(middle):

0 commit comments

Comments
 (0)