Skip to content

Commit 800ff30

Browse files
committed
shrink after Hlist!
1 parent 3a32194 commit 800ff30

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/matplotlib/mathtext.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ def get_underline_thickness(self, font, fontsize, dpi):
11871187
# get any smaller
11881188
NUM_SIZE_LEVELS = 6
11891189
# Percentage of x-height of additional horiz. space after sub/superscripts
1190-
SCRIPT_SPACE = -0.10
1190+
SCRIPT_SPACE = 0.07
11911191
# Percentage of x-height that sub/superscripts drop below the baseline
11921192
SUBDROP = 0.3
11931193
# Percentage of x-height that superscripts drop below the baseline
@@ -1196,7 +1196,7 @@ def get_underline_thickness(self, font, fontsize, dpi):
11961196
SUB1 = 0.0
11971197
# Percentage of x-height that supercripts are offset relative to the subscript
11981198
# for slanted nuclei
1199-
DELTA = 0.15
1199+
DELTA = 0.10
12001200

12011201
class MathTextWarning(Warning):
12021202
pass
@@ -2631,7 +2631,6 @@ def is_slanted(self, nucleus):
26312631

26322632
def subsuper(self, s, loc, toks):
26332633
assert(len(toks)==1)
2634-
# print 'subsuper', toks
26352634

26362635
nucleus = None
26372636
sub = None
@@ -2686,6 +2685,8 @@ def subsuper(self, s, loc, toks):
26862685
"Subscript/superscript sequence is too long. "
26872686
"Use braces { } to remove ambiguity.")
26882687

2688+
last_char = nucleus.children[-2] if isinstance(nucleus,Hlist) else nucleus
2689+
26892690
state = self.get_state()
26902691
rule_thickness = state.font_output.get_underline_thickness(
26912692
state.font, state.fontsize, state.dpi)
@@ -2735,25 +2736,26 @@ def subsuper(self, s, loc, toks):
27352736
shift_down = SUBDROP * xHeight
27362737
if super is None:
27372738
# node757
2738-
sub.shrink()
27392739
x = Hlist([sub])
2740+
x.shrink()
27402741
x.width += SCRIPT_SPACE * xHeight
27412742
shift_down = max(shift_down, SUB1)
27422743
clr = x.height - (abs(xHeight * 4.0) / 5.0)
27432744
shift_down = max(shift_down, clr)
27442745
x.shift_amount = shift_down / 2.
27452746
else:
2746-
super.shrink()
2747-
x = Hlist([super])
2747+
if self.is_slanted(last_char):
2748+
x = Hlist([Kern(DELTA * super.height),super])
2749+
else:
2750+
x = Hlist([super])
2751+
x.shrink()
27482752
x.width += SCRIPT_SPACE * xHeight
27492753
shift_up = SUP1 * xHeight
2750-
if self.is_slanted(nucleus):
2751-
x = Hlist([Kern(DELTA * x.height),x])
27522754
if sub is None:
27532755
x.shift_amount = -shift_up
27542756
else: # Both sub and superscript
2755-
sub.shrink()
27562757
y = Hlist([sub])
2758+
y.shrink()
27572759
y.width += SCRIPT_SPACE * xHeight
27582760
shift_down = max(shift_down, SUB1 * xHeight)
27592761
# If sub and superscript collide, move sup up

0 commit comments

Comments
 (0)