@@ -1187,8 +1187,8 @@ def get_underline_thickness(self, font, fontsize, dpi):
1187
1187
# get any smaller
1188
1188
NUM_SIZE_LEVELS = 6
1189
1189
# Percentage of x-height of additional horiz. space after sub/superscripts
1190
- SCRIPT_SPACE = {'cm' : 0.05 ,
1191
- 'stix' : 0.10 ,
1190
+ SCRIPT_SPACE = {'cm' : 0.025 ,
1191
+ 'stix' : 0.20 ,
1192
1192
'stixsans' : 0.10 ,
1193
1193
'arevsans' : 0.10 }
1194
1194
## Percentage of x-height that sub/superscripts drop below the baseline
@@ -1212,12 +1212,18 @@ def get_underline_thickness(self, font, fontsize, dpi):
1212
1212
'stix' : 0.6 ,
1213
1213
'stixsans' : 0.5 ,
1214
1214
'arevsans' : 0.8 }
1215
- # Percentage of x-height that supercripts are offset relative to the subscript
1216
- # for slanted nuclei
1215
+ # Percentage of x-height that sub/ supercripts are offset relative to the
1216
+ # nucleus end
1217
1217
DELTA = {'cm' : 0.10 ,
1218
- 'stix' : 0.15 ,
1218
+ 'stix' : 0.10 ,
1219
1219
'stixsans' : 0.25 ,
1220
1220
'arevsans' : 0.12 }
1221
+ # Additional percentage of last character height that supercripts are offset
1222
+ # relative to the subscript for slanted nuclei
1223
+ DELTASLANTED = {'cm' : 0.05 ,
1224
+ 'stix' : 0.05 ,
1225
+ 'stixsans' : 0.05 ,
1226
+ 'arevsans' : 0.12 }
1221
1227
# Percentage of x-height that supercripts are offset relative to the subscript
1222
1228
# for integrals
1223
1229
DELTAINTEGRAL = {'cm' : 0.5 ,
@@ -2714,8 +2720,16 @@ def subsuper(self, s, loc, toks):
2714
2720
2715
2721
last_char = nucleus
2716
2722
if isinstance (nucleus ,Hlist ):
2717
- if len (nucleus .children ) >= 2 :
2718
- last_char = nucleus.children [- 2 ]
2723
+ # remove kerns
2724
+ new_children = []
2725
+ for child in nucleus .children :
2726
+ if not isinstance (child , Kern ):
2727
+ new_children .append (child )
2728
+ nucleus = Hlist (new_children , do_kern = False )
2729
+ if len (new_children ):
2730
+ last_char = new_children [- 1 ]
2731
+ else :
2732
+ nucleus = Hlist ([nucleus ],do_kern = False )
2719
2733
2720
2734
state = self .get_state ()
2721
2735
rule_thickness = state .font_output .get_underline_thickness (
@@ -2733,7 +2747,6 @@ def subsuper(self, s, loc, toks):
2733
2747
else :
2734
2748
fs = 'cm'
2735
2749
2736
-
2737
2750
if napostrophes :
2738
2751
if super is None :
2739
2752
super = Hlist ([])
@@ -2774,50 +2787,43 @@ def subsuper(self, s, loc, toks):
2774
2787
lc_baseline = 0
2775
2788
if self .is_dropsub (last_char ):
2776
2789
lc_baseline = last_char .depth
2777
- if super is None :
2778
- # node757
2790
+
2791
+ # Compute kerning for sub and super
2792
+ superkern = DELTA [fs ] * xHeight
2793
+ subkern = DELTA [fs ] * xHeight
2794
+ if self .is_slanted (last_char ):
2795
+ superkern += DELTASLANTED [fs ] * xHeight
2779
2796
if self .is_dropsub (last_char ):
2780
- x = Hlist ([ Kern ( - DELTA [fs ] * last_char . height ), sub ])
2797
+ subkern = - DELTAINTEGRAL [fs ] * lc_height
2781
2798
else :
2782
- x = Hlist ([sub ])
2799
+ subkern = 0.25 * DELTA [fs ] * lc_height
2800
+
2801
+ if super is None :
2802
+ # node757
2803
+ x = Hlist ([Kern (subkern ), sub ])
2783
2804
x .shrink ()
2784
- x .width += SCRIPT_SPACE [fs ] * xHeight
2785
2805
shift_down = max (lc_baseline + SUBDROP [fs ] * xHeight ,
2786
2806
SUB1 [fs ] * xHeight )
2787
2807
if not self .is_dropsub (last_char ):
2788
2808
shift_down /= 2
2789
2809
x .shift_amount = shift_down
2790
2810
else :
2791
- if self .is_dropsub (last_char ):
2792
- delta = DELTAINTEGRAL [fs ]
2793
- else :
2794
- delta = DELTA [fs ]
2795
-
2796
- if self .is_slanted (last_char ):
2797
- x = Hlist ([Kern (delta * last_char .height ),super ])
2798
- else :
2799
- x = Hlist ([super ])
2811
+ x = Hlist ([Kern (superkern ), super ])
2800
2812
x .shrink ()
2801
- x .width += SCRIPT_SPACE [fs ] * xHeight
2802
2813
if self .is_dropsub (last_char ):
2803
2814
shift_up = lc_height - SUBDROP [fs ] * xHeight
2804
2815
else :
2805
2816
shift_up = SUP1 [fs ] * xHeight
2806
2817
if sub is None :
2807
2818
x .shift_amount = - shift_up
2808
2819
else : # Both sub and superscript
2809
- if self .is_dropsub (last_char ):
2810
- y = Hlist ([Kern (- DELTA [fs ] * last_char .height ),sub ])
2811
- else :
2812
- y = Hlist ([sub ])
2813
- #y = Hlist([sub])
2820
+ y = Hlist ([Kern (subkern ),sub ])
2814
2821
y .shrink ()
2815
- y .width += SCRIPT_SPACE [fs ] * xHeight
2816
2822
if self .is_dropsub (last_char ):
2817
2823
shift_down = lc_baseline + SUBDROP [fs ] * xHeight
2818
2824
else :
2819
2825
shift_down = SUB2 [fs ] * xHeight
2820
- # If sub and superscript collide, move sup up
2826
+ # If sub and superscript collide, move super up
2821
2827
clr = (2.0 * rule_thickness -
2822
2828
((shift_up - x .depth ) - (y .height - shift_down )))
2823
2829
if clr > 0. :
@@ -2827,7 +2833,8 @@ def subsuper(self, s, loc, toks):
2827
2833
y ])
2828
2834
x .shift_amount = shift_down
2829
2835
2830
- result = Hlist ([nucleus , x ])
2836
+ x .width += SCRIPT_SPACE [fs ] * xHeight
2837
+ result = Hlist ([nucleus , x ], do_kern = False )
2831
2838
return [result ]
2832
2839
2833
2840
def _genfrac (self , ldelim , rdelim , rule , style , num , den ):
0 commit comments