@@ -1187,15 +1187,15 @@ 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.025 ,
1191
- 'stix' : 0.20 ,
1190
+ SCRIPT_SPACE = {'cm' : 0.05 ,
1191
+ 'stix' : 0.10 ,
1192
1192
'stixsans' : 0.10 ,
1193
- 'arevsans' : 0.10 }
1193
+ 'arevsans' : 0.05 }
1194
1194
## Percentage of x-height that sub/superscripts drop below the baseline
1195
- SUBDROP = {'cm' : 0.3 ,
1195
+ SUBDROP = {'cm' : 0.2 ,
1196
1196
'stix' : 0.4 ,
1197
1197
'stixsans' : 0.4 ,
1198
- 'arevsans' : 0.3 }
1198
+ 'arevsans' : 0.4 }
1199
1199
# Percentage of x-height that superscripts are raised from the baseline
1200
1200
SUP1 = {'cm' : 0.45 ,
1201
1201
'stix' : 0.8 ,
@@ -1211,25 +1211,25 @@ def get_underline_thickness(self, font, fontsize, dpi):
1211
1211
SUB2 = {'cm' : 0.3 ,
1212
1212
'stix' : 0.6 ,
1213
1213
'stixsans' : 0.5 ,
1214
- 'arevsans' : 0.8 }
1214
+ 'arevsans' : 0.5 }
1215
1215
# Percentage of x-height that sub/supercripts are offset relative to the
1216
- # nucleus end
1217
- DELTA = {'cm' : 0.10 ,
1218
- 'stix' : 0.10 ,
1219
- 'stixsans' : 0.25 ,
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 ,
1216
+ # nucleus edge
1217
+ DELTA = {'cm' : 0.025 ,
1224
1218
'stix' : 0.05 ,
1225
1219
'stixsans' : 0.05 ,
1226
- 'arevsans' : 0.12 }
1227
- # Percentage of x-height that supercripts are offset relative to the subscript
1228
- # for integrals
1229
- DELTAINTEGRAL = {'cm' : 0.5 ,
1230
- 'stix' : 0.5 ,
1231
- 'stixsans' : 0.4 ,
1232
- 'arevsans' : 0.5 }
1220
+ 'arevsans' : 0.05 }
1221
+ # Additional percentage of last character height above 2/3 of the x-height that
1222
+ # supercripts are offset relative to the subscript for slanted nuclei
1223
+ DELTASLANTED = {'cm' : 0.4 ,
1224
+ 'stix' : 0.3 ,
1225
+ 'stixsans' : 0.5 ,
1226
+ 'arevsans' : 0.2 }
1227
+ # Percentage of x-height that supercripts and subscripts are offset for
1228
+ # integrals
1229
+ DELTAINTEGRAL = {'cm' : 0.325 ,
1230
+ 'stix' : 0.3 ,
1231
+ 'stixsans' : 0.3 ,
1232
+ 'arevsans' : 0.3 }
1233
1233
1234
1234
class MathTextWarning (Warning ):
1235
1235
pass
@@ -2718,24 +2718,35 @@ def subsuper(self, s, loc, toks):
2718
2718
"Subscript/superscript sequence is too long. "
2719
2719
"Use braces { } to remove ambiguity." )
2720
2720
2721
+ # We remove kerning for consistency (otherwise it will compute kerning
2722
+ # based on non-shrinked characters and may put them very close together
2723
+ # when superscripted)
2724
+ # We change the width of the last character to match the advance to
2725
+ # consider some fonts with weird metrics: e.g. stix's f has a width of
2726
+ # 7.75 and a kerning of -4.0 for an advance of 3.72, and we want to put
2727
+ # the superscript at the advance
2721
2728
last_char = nucleus
2722
2729
if isinstance (nucleus ,Hlist ):
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 )
2730
+ new_children = nucleus .children
2729
2731
if len (new_children ):
2732
+ # remove last kern
2733
+ if isinstance (new_children [- 1 ],Kern ):
2734
+ new_children = new_children [:- 1 ]
2730
2735
last_char = new_children [- 1 ]
2736
+ last_char .width = last_char ._metrics .advance
2737
+ nucleus = Hlist (new_children , do_kern = False )
2731
2738
else :
2739
+ last_char .width = last_char ._metrics .advance
2732
2740
nucleus = Hlist ([nucleus ],do_kern = False )
2733
2741
2742
+
2734
2743
state = self .get_state ()
2735
2744
rule_thickness = state .font_output .get_underline_thickness (
2736
2745
state .font , state .fontsize , state .dpi )
2737
2746
xHeight = state .font_output .get_xheight (
2738
2747
state .font , state .fontsize , state .dpi )
2748
+ print (last_char , last_char .height ,
2749
+ xHeight )
2739
2750
2740
2751
fs = rcParams ['mathtext.fontset' ]
2741
2752
# If a custom fontset is used, check if it is Arev Sans, otherwise use
@@ -2747,6 +2758,7 @@ def subsuper(self, s, loc, toks):
2747
2758
else :
2748
2759
fs = 'cm'
2749
2760
2761
+
2750
2762
if napostrophes :
2751
2763
if super is None :
2752
2764
super = Hlist ([])
@@ -2792,11 +2804,13 @@ def subsuper(self, s, loc, toks):
2792
2804
superkern = DELTA [fs ] * xHeight
2793
2805
subkern = DELTA [fs ] * xHeight
2794
2806
if self .is_slanted (last_char ):
2795
- superkern += DELTASLANTED [fs ] * xHeight
2807
+ superkern += DELTASLANTED [fs ] * ( lc_height - xHeight * 2. / 3. )
2796
2808
if self .is_dropsub (last_char ):
2797
- subkern = - DELTAINTEGRAL [fs ] * lc_height
2809
+ subkern = (2 * DELTA [fs ] - DELTAINTEGRAL [fs ]) * lc_height
2810
+ superkern = (2 * DELTA [fs ] + DELTAINTEGRAL [fs ]) * lc_height
2798
2811
else :
2799
- subkern = 0.25 * DELTA [fs ] * lc_height
2812
+ subkern = - DELTA [fs ] * xHeight
2813
+ #subkern, superkern =0,0
2800
2814
2801
2815
if super is None :
2802
2816
# node757
@@ -2833,7 +2847,8 @@ def subsuper(self, s, loc, toks):
2833
2847
y ])
2834
2848
x .shift_amount = shift_down
2835
2849
2836
- x .width += SCRIPT_SPACE [fs ] * xHeight
2850
+ if not self .is_dropsub (last_char ):
2851
+ x .width += SCRIPT_SPACE [fs ] * xHeight
2837
2852
result = Hlist ([nucleus , x ], do_kern = False )
2838
2853
return [result ]
2839
2854
0 commit comments