8000 Fully fold overset/underset into _genset. by anntzer · Pull Request #19499 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fully fold overset/underset into _genset. #19499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2859,29 +2859,28 @@ 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)
cannotation.hpack(width, 'exactly')
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
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
0