Skip to content

Commit 5b78b6f

Browse files
committed
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.
1 parent 92b4bc3 commit 5b78b6f

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
@@ -2859,29 +2859,28 @@ def binom(self, s, loc, toks):
28592859
return self._genfrac('(', ')', 0.0, self._MathStyle.TEXTSTYLE,
28602860
num, den)
28612861

2862-
def _genset(self, state, annotation, body, overunder):
2862+
def _genset(self, s, loc, toks):
2863+
(annotation, body), = toks
2864+
state = self.get_state()
28632865
thickness = state.font_output.get_underline_thickness(
28642866
state.font, state.fontsize, state.dpi)
28652867

28662868
annotation.shrink()
2867-
28682869
cannotation = HCentered([annotation])
28692870
cbody = HCentered([body])
28702871
width = max(cannotation.width, cbody.width)
28712872
cannotation.hpack(width, 'exactly')
28722873
cbody.hpack(width, 'exactly')
28732874

28742875
vgap = thickness * 3
2875-
if overunder == "under":
2876+
if s[loc + 1] == "u": # \underset
28762877
vlist = Vlist([cbody, # body
28772878
Vbox(0, vgap), # space
28782879
cannotation # annotation
28792880
])
28802881
# Shift so the body sits in the same vertical position
2881-
shift_amount = cbody.depth + cannotation.height + vgap
2882-
2883-
vlist.shift_amount = shift_amount
2884-
else:
2882+
vlist.shift_amount = cbody.depth + cannotation.height + vgap
2883+
else: # \overset
28852884
vlist = Vlist([cannotation, # annotation
28862885
Vbox(0, vgap), # space
28872886
cbody # body
@@ -2891,6 +2890,8 @@ def _genset(self, state, annotation, body, overunder):
28912890
# an Hlist and extend it with an Hbox(0, horizontal_gap)
28922891
return vlist
28932892

2893+
overset = underset = _genset
2894+
28942895
def sqrt(self, s, loc, toks):
28952896
(root, body), = toks
28962897
state = self.get_state()
@@ -2951,24 +2952,6 @@ def overline(self, s, loc, toks):
29512952
hlist = Hlist([rightside])
29522953
return [hlist]
29532954

2954-
def overset(self, s, loc, toks):
2955-
assert len(toks) == 1
2956-
assert len(toks[0]) == 2
2957-
2958-
state = self.get_state()
2959-
annotation, body = toks[0]
2960-
2961-
return self._genset(state, annotation, body, overunder="over")
2962-
2963-
def underset(self, s, loc, toks):
2964-
assert len(toks) == 1
2965-
assert len(toks[0]) == 2
2966-
2967-
state = self.get_state()
2968-
annotation, body = toks[0]
2969-
2970-
return self._genset(state, annotation, body, overunder="under")
2971-
29722955
def _auto_sized_delimiter(self, front, middle, back):
29732956
state = self.get_state()
29742957
if len(middle):

0 commit comments

Comments
 (0)