Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68d99be

Browse files
committed
apply different rules for dropsub (integrals)
1 parent 14a05ef commit 68d99be

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

lib/matplotlib/mathtext.py

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,13 +1187,13 @@ 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 = {'cm': 0.03,
1190+
SCRIPT_SPACE = {'cm': 0.05,
11911191
'stix': 0.10,
11921192
'stixsans': 0.10}
11931193
## Percentage of x-height that sub/superscripts drop below the baseline
11941194
SUBDROP = {'cm': 0.3,
1195-
'stix': 0.3,
1196-
'stixsans': 0.3}
1195+
'stix': 0.4,
1196+
'stixsans': 0.4}
11971197
# Percentage of x-height that superscripts drop below the baseline
11981198
SUP1 = {'cm': 0.4,
11991199
'stix': 0.8,
@@ -1212,6 +1212,11 @@ def get_underline_thickness(self, font, fontsize, dpi):
12121212
DELTA = {'cm': 0.10,
12131213
'stix': 0.15,
12141214
'stixsans': 0.25}
1215+
# Percentage of x-height that supercripts are offset relative to the subscript
1216+
# for integrals
1217+
DELTAINTEGRAL = {'cm': 0.5,
1218+
'stix': 0.5,
1219+
'stixsans': 0.4}
12151220

12161221
class MathTextWarning(Warning):
12171222
pass
@@ -2752,35 +2757,53 @@ def subsuper(self, s, loc, toks):
27522757
return [result]
27532758

27542759
# Handle regular sub/superscripts
2755-
shift_up = nucleus.height - SUBDROP[fs] * xHeight
2756-
if self.is_dropsub(nucleus):
2757-
shift_down = nucleus.depth + SUBDROP[fs] * xHeight
2758-
else:
2759-
shift_down = SUBDROP[fs] * xHeight
2760+
lc_height = last_char.height
2761+
lc_baseline = 0
2762+
if self.is_dropsub(last_char):
2763+
lc_baseline = last_char.depth
27602764
if super is None:
27612765
# node757
2762-
x = Hlist([sub])
2766+
if self.is_dropsub(last_char):
2767+
x = Hlist([Kern(-DELTA[fs] * last_char.height),sub])
2768+
else:
2769+
x = Hlist([sub])
27632770
x.shrink()
27642771
x.width += SCRIPT_SPACE[fs] * xHeight
2765-
shift_down = max(shift_down, SUB1[fs] * xHeight)
2766-
#clr = x.height - (abs(xHeight * 4.0) / 5.0)
2767-
#shift_down = max(shift_down, clr)
2768-
x.shift_amount = shift_down / 2.
2772+
shift_down = max(lc_baseline + SUBDROP[fs] * xHeight,
2773+
SUB1[fs] * xHeight)
2774+
if not self.is_dropsub(last_char):
2775+
shift_down /= 2
2776+
x.shift_amount = shift_down
27692777
else:
2778+
if self.is_dropsub(last_char):
2779+
delta = DELTAINTEGRAL[fs]
2780+
else:
2781+
delta = DELTA[fs]
2782+
27702783
if self.is_slanted(last_char):
2771-
x = Hlist([Kern(DELTA[fs] * super.height),super])
2784+
x = Hlist([Kern(delta * last_char.height),super])
27722785
else:
27732786
x = Hlist([super])
27742787
x.shrink()
27752788
x.width += SCRIPT_SPACE[fs] * xHeight
2776-
shift_up = SUP1[fs] * xHeight
2789+
if self.is_dropsub(last_char):
2790+
shift_up = lc_height - SUBDROP[fs] * xHeight
2791+
else:
2792+
shift_up = SUP1[fs] * xHeight
27772793
if sub is None:
27782794
x.shift_amount = -shift_up
27792795
else: # Both sub and superscript
2780-
y = Hlist([sub])
2796+
if self.is_dropsub(last_char):
2797+
y = Hlist([Kern(-DELTA[fs] * last_char.height),sub])
2798+
else:
2799+
y = Hlist([sub])
2800+
#y = Hlist([sub])
27812801
y.shrink()
27822802
y.width += SCRIPT_SPACE[fs] * xHeight
2783-
shift_down = max(shift_down, SUB2[fs] * xHeight)
2803+
if self.is_dropsub(last_char):
2804+
shift_down = lc_baseline + SUBDROP[fs] * xHeight
2805+
else:
2806+
shift_down = SUB2[fs] * xHeight
27842807
# If sub and superscript collide, move sup up
27852808
clr = (2.0 * rule_thickness -
27862809
((shift_up - x.depth) - (y.height - shift_down)))

lib/matplotlib/tests/test_mathtext.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
r'$\dotplus$ $\doteq$ $\doteqdot$ $\ddots$',
101101
r'$x_kx^py^{p-2} d_i^jb_jc_kd x^j_i E^0 E^0_u$', # github issue #4873
102102
r'${x}_{k}{x}^{p}{y}^{p-2} {d}_{i}^{j}{b}_{j}{c}_{k}{d} {x}^{j}_{i}{E}^{0}{E}^0_u$',
103+
r'${\int}_x^x x\oint_x^x x\int_{X}^{X}x\int_x x \int^x x \int_{x} x\int^{x}{\int}_{x} x{\int}^{x}_{x}x$',
104+
103105
]
104106

105107
digits = "0123456789"

0 commit comments

Comments
 (0)