@@ -1187,13 +1187,13 @@ def get_underline_thickness(self, font, fontsize, dpi):
11871187# get any smaller
11881188NUM_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
11941194SUBDROP = {'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
11981198SUP1 = {'cm' : 0.4 ,
11991199 'stix' : 0.8 ,
@@ -1212,6 +1212,11 @@ def get_underline_thickness(self, font, fontsize, dpi):
12121212DELTA = {'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
12161221class 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 )))
0 commit comments