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

Skip to content

Commit a99c3bc

Browse files
committed
fix integrals
1 parent 14a05ef commit a99c3bc

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

lib/matplotlib/mathtext.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ def get_underline_thickness(self, font, fontsize, dpi):
11911191
'stix': 0.10,
11921192
'stixsans': 0.10}
11931193
## Percentage of x-height that sub/superscripts drop below the baseline
1194-
SUBDROP = {'cm': 0.3,
1194+
SUBDROP = {'cm': 0.2,
11951195
'stix': 0.3,
11961196
'stixsans': 0.3}
11971197
# Percentage of x-height that superscripts drop below the baseline
@@ -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.5}
12151220

12161221
class MathTextWarning(Warning):
12171222
pass
@@ -2757,9 +2762,13 @@ def subsuper(self, s, loc, toks):
27572762
shift_down = nucleus.depth + SUBDROP[fs] * xHeight
27582763
else:
27592764
shift_down = SUBDROP[fs] * xHeight
2765+
integral = (nucleus.height + nucleus.depth) > 2 * xHeight
27602766
if super is None:
27612767
# node757
2762-
x = Hlist([sub])
2768+
if integral:
2769+
x = Hlist([Kern(-DELTA[fs] * nucleus.height),sub])
2770+
else:
2771+
x = Hlist([sub])
27632772
x.shrink()
27642773
x.width += SCRIPT_SPACE[fs] * xHeight
27652774
shift_down = max(shift_down, SUB1[fs] * xHeight)
@@ -2768,16 +2777,25 @@ def subsuper(self, s, loc, toks):
27682777
x.shift_amount = shift_down / 2.
27692778
else:
27702779
if self.is_slanted(last_char):
2771-
x = Hlist([Kern(DELTA[fs] * super.height),super])
2780+
f = DELTA[fs]
2781+
if integral: f = DELTAINTEGRAL[fs]
2782+
x = Hlist([Kern(f * nucleus.height),super])
27722783
else:
27732784
x = Hlist([super])
27742785
x.shrink()
27752786
x.width += SCRIPT_SPACE[fs] * xHeight
2776-
shift_up = SUP1[fs] * xHeight
2787+
if integral:
2788+
shift_up = max(shift_up,SUP1[fs] * xHeight)
2789+
else:
2790+
shift_up = SUP1[fs] * xHeight
27772791
if sub is None:
27782792
x.shift_amount = -shift_up
27792793
else: # Both sub and superscript
2780-
y = Hlist([sub])
2794+
if integral:
2795+
y = Hlist([Kern(-DELTA[fs] * nucleus.height),sub])
2796+
else:
2797+
y = Hlist([sub])
2798+
#y = Hlist([sub])
27812799
y.shrink()
27822800
y.width += SCRIPT_SPACE[fs] * xHeight
27832801
shift_down = max(shift_down, SUB2[fs] * xHeight)

0 commit comments

Comments
 (0)