FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add overset/underset whatsnew entry by aitikgupta · Pull Request #19497 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 11 additions & 0 deletions doc/users/next_whats_new/mathtext.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
``matplotlib.mathtext`` now supports *overset* and *underset* LaTeX symbols
---------------------------------------------------------------------------

`.mathtext` now supports *overset* and *underset*, called as
``\overset{annotation}{body}`` or ``\underset{annotation}{body}``, where
*annotation* is the text "above" or "below" the *body*.

.. plot::

math_expr = r"$ x \overset{f}{\rightarrow} y \underset{f}{\leftarrow} z $"
plt.text(0.4, 0.5, math_expr, usetex=False)
34 changes: 17 additions & 17 deletions lib/matplotlib/_mathtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

Back | FazBrowse Home | New Git URL