@@ -1187,49 +1187,49 @@ 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 ,
1192
- 'stixsans' : 0.10 ,
1193
- 'arevsans' : 0.10 }
1190
+ SCRIPT_SPACE = {'cm' : 0.075 ,
1191
+ 'stix' : 0.10 ,
1192
+ 'stixsans' : 0.05 ,
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 ,
1202
1202
'stixsans' : 0.8 ,
1203
1203
'arevsans' : 0.7 }
1204
1204
# Percentage of x-height that subscripts drop below the baseline
1205
- SUB1 = {'cm' : 0.4 ,
1206
- 'stix' : 0.6 ,
1207
- 'stixsans' : 0.6 ,
1208
- 'arevsans' : 0.6 }
1205
+ SUB1 = {'cm' : 0.2 ,
1206
+ 'stix' : 0.3 ,
1207
+ 'stixsans' : 0.3 ,
1208
+ 'arevsans' : 0.3 }
1209
1209
# Percentage of x-height that subscripts drop below the baseline when a
1210
1210
# superscript is present
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 for non-slanted nuclei
1217
+ DELTA = {'cm' : 0.075 ,
1224
1218
'stix' : 0.05 ,
1225
- '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 }
1219
+ 'stixsans' : 0.025 ,
1220
+ 'arevsans' : 0.025 }
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.3 ,
1224
+ 'stix' : 0.3 ,
1225
+ 'stixsans' : 0.6 ,
1226
+ 'arevsans' : 0.2 }
1227
+ # Percentage of x-height that supercripts and subscripts are offset for
1228
+ # integrals
1229
+ DELTAINTEGRAL = {'cm' : 0.3 ,
1230
+ 'stix' : 0.3 ,
1231
+ 'stixsans' : 0.3 ,
1232
+ 'arevsans' : 0.3 }
1233
1233
1234
1234
class MathTextWarning (Warning ):
1235
1235
pass
@@ -2718,35 +2718,12 @@ def subsuper(self, s, loc, toks):
2718
2718
"Subscript/superscript sequence is too long. "
2719
2719
"Use braces { } to remove ambiguity." )
2720
2720
2721
- last_char = nucleus
2722
- 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 )
2729
- if len (new_children ):
2730
- last_char = new_children [- 1 ]
2731
- else :
2732
- nucleus = Hlist ([nucleus ],do_kern = False )
2733
-
2734
2721
state = self .get_state ()
2735
2722
rule_thickness = state .font_output .get_underline_thickness (
2736
2723
state .font , state .fontsize , state .dpi )
2737
2724
xHeight = state .font_output .get_xheight (
2738
2725
state .font , state .fontsize , state .dpi )
2739
2726
2740
- fs = rcParams ['mathtext.fontset' ]
2741
- # If a custom fontset is used, check if it is Arev Sans, otherwise use
2742
- # CM parameters.
2743
- if fs == 'custom' :
2744
- if (rcParams ['mathtext.rm' ] == 'sans' and
2745
- rcParams ['font.sans-serif' ][0 ].lower () == 'Arev Sans' .lower ()):
2746
- fs = 'arevsans'
2747
- else :
2748
- fs = 'cm'
2749
-
2750
2727
if napostrophes :
2751
2728
if super is None :
2752
2729
super = Hlist ([])
@@ -2782,6 +2759,38 @@ def subsuper(self, s, loc, toks):
2782
2759
result = Hlist ([vlist ])
2783
2760
return [result ]
2784
2761
2762
+ # We remove kerning for consistency (otherwise it will compute kerning
2763
+ # based on non-shrinked characters and may put them very close together
2764
+ # when superscripted)
2765
+ # We change the width of the last character to match the advance to
2766
+ # consider some fonts with weird metrics: e.g. stix's f has a width of
2767
+ # 7.75 and a kerning of -4.0 for an advance of 3.72, and we want to put
2768
+ # the superscript at the advance
2769
+ last_char = nucleus
2770
+ if isinstance (nucleus ,Hlist ):
2771
+ new_children = nucleus .children
2772
+ if len (new_children ):
2773
+ # remove last kern
2774
+ if isinstance (new_children [- 1 ],Kern ):
2775
+ new_children = new_children [:- 1 ]
2776
+ last_char = new_children [- 1 ]
2777
+ last_char .width = last_char ._metrics .advance
2778
+ # create new Hlist without kerning
2779
+ nucleus = Hlist (new_children , do_kern = False )
2780
+ else :
2781
+ last_char .width = last_char ._metrics .advance
2782
+ nucleus = Hlist ([nucleus ])
2783
+
2784
+ fs = rcParams ['mathtext.fontset' ]
2785
+ # If a custom fontset is used, check if it is Arev Sans, otherwise use
2786
+ # CM parameters.
2787
+ if fs == 'custom' :
2788
+ if (rcParams ['mathtext.rm' ] == 'sans' and
2789
+ rcParams ['font.sans-serif' ][0 ].lower () == 'Arev Sans' .lower ()):
2790
+ fs = 'arevsans'
2791
+ else :
2792
+ fs = 'cm'
2793
+
2785
2794
# Handle regular sub/superscripts
2786
2795
lc_height = last_char .height
2787
2796
lc_baseline = 0
@@ -2792,20 +2801,22 @@ def subsuper(self, s, loc, toks):
2792
2801
superkern = DELTA [fs ] * xHeight
2793
2802
subkern = DELTA [fs ] * xHeight
2794
2803
if self .is_slanted (last_char ):
2795
- superkern += DELTASLANTED [fs ] * xHeight
2804
+ superkern += DELTA [fs ] * xHeight
2805
+ superkern += DELTASLANTED [fs ] * (lc_height - xHeight * 2. / 3. )
2796
2806
if self .is_dropsub (last_char ):
2797
- subkern = - DELTAINTEGRAL [fs ] * lc_height
2807
+ subkern = (3 * DELTA [fs ] - DELTAINTEGRAL [fs ]) * lc_height
2808
+ superkern = (3 * DELTA [fs ] + DELTAINTEGRAL [fs ]) * lc_height
2798
2809
else :
2799
- subkern = 0.25 * DELTA [ fs ] * lc_height
2810
+ subkern = 0
2800
2811
2801
2812
if super is None :
2802
2813
# node757
2803
2814
x = Hlist ([Kern (subkern ), sub ])
2804
2815
x .shrink ()
2805
- shift_down = max ( lc_baseline + SUBDROP [ fs ] * xHeight ,
2806
- SUB1 [fs ] * xHeight )
2807
- if not self . is_dropsub ( last_char ) :
2808
- shift_down /= 2
2816
+ if self . is_dropsub ( last_char ):
2817
+ shift_down = lc_baseline + SUBDROP [fs ] * xHeight
2818
+ else :
2819
+ shift_down = SUB1 [ fs ] * xHeight
2809
2820
x .shift_amount = shift_down
2810
2821
else :
2811
2822
x = Hlist ([Kern (superkern ), super ])
@@ -2833,8 +2844,9 @@ def subsuper(self, s, loc, toks):
2833
2844
y ])
2834
2845
x .shift_amount = shift_down
2835
2846
2836
- x .width += SCRIPT_SPACE [fs ] * xHeight
2837
- result = Hlist ([nucleus , x ], do_kern = False )
2847
+ if not self .is_dropsub (last_char ):
2848
+ x .width += SCRIPT_SPACE [fs ] * xHeight
2849
+ result = Hlist ([nucleus , x ])
2838
2850
return [result ]
2839
2851
2840
2852
def _genfrac (self , ldelim , rdelim , rule , style , num , den ):
0 commit comments