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

Slightly better positioning of subscripts and superscripts of fractions by tfpf · Pull Request #21850 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type 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
37 changes: 28 additions & 9 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 @@ -1830,6 +1830,7 @@ def set_names_and_parse_actions():
| p.underset
| p.sqrt
| p.overline
| p.auto_delim
)

p.simple <<= (
Expand Down Expand Up @@ -2206,6 +2207,16 @@ def subsuper(self, s, loc, toks):
result = Hlist([vlist])
return [result]

# Set the minimum shifts for the superscript and subscript (node756).
constants = _get_font_constant_set(state)
if isinstance(nucleus, Char):
shift_up = 0
shift_down = 0
else:
drop_amount = constants.subdrop * xHeight * SHRINK_FACTOR
shift_up = nucleus.height - drop_amount
shift_down = nucleus.depth + drop_amount

# We remove kerning on the last character for consistency (otherwise
# it will compute kerning based on non-shrunk characters and may put
# them too close together when superscripted)
Expand All @@ -2232,7 +2243,6 @@ def subsuper(self, s, loc, toks):
nucleus = Hlist([nucleus])

# Handle regular sub/superscripts
constants = _get_font_constant_set(state)
lc_height = last_char.height
lc_baseline = 0
if self.is_dropsub(last_char):
Expand All @@ -2254,35 +2264,44 @@ def subsuper(self, s, loc, toks):
subkern = 0

if super is None:
# node757
# Align subscript without superscript (node757).
x = Hlist([Kern(subkern), sub])
x.shrink()
if self.is_dropsub(last_char):
shift_down = lc_baseline + constants.subdrop * xHeight
else:
shift_down = constants.sub1 * xHeight
shift_down = max(shift_down, constants.sub1 * xHeight,
x.height - xHeight * 4 / 5)
x.shift_amount = shift_down
else:
# Align superscript (node758).
x = Hlist([Kern(superkern), super])
x.shrink()
if self.is_dropsub(last_char):
shift_up = lc_height - constants.subdrop * xHeight
else:
shift_up = constants.sup1 * xHeight
shift_up = max(shift_up, constants.sup1 * xHeight,
x.depth + xHeight / 4)
if sub is None:
x.shift_amount = -shift_up
else: # Both sub and superscript
else:
# Align subscript with superscript (node759).
y = Hlist([Kern(subkern), sub])
y.shrink()
if self.is_dropsub(last_char):
shift_down = lc_baseline + constants.subdrop * xHeight
else:
shift_down = constants.sub2 * xHeight
# If sub and superscript collide, move super up
clr = (2.0 * rule_thickness -
shift_down = max(shift_down, constants.sub2 * xHeight)
# If the subscript and superscript are too close to each other,
# move the subscript down.
clr = (4 * rule_thickness -
((shift_up - x.depth) - (y.height - shift_down)))
if clr > 0.:
shift_up += clr
shift_down += clr
clr = xHeight * 4 / 5 - shift_up + x.depth
if clr > 0:
shift_up += clr
shift_down -= clr
x = Vlist([
x,
Kern((shift_up - x.depth) - (y.height - shift_down)),
Expand Down

Back | FazBrowse Home | New Git URL