@@ -2758,6 +2758,9 @@ def subsuper(self, s, loc, toks):
2758
2758
2759
2759
def _genfrac (self , ldelim , rdelim , rule , style , num , den ):
2760
2760
state = self .get_state ()
2761
+ cap_height = state .font_output .get_metrics (
2762
+ state .font , mpl .rcParams ['mathtext.default' ],
2763
+ 'H' , state .fontsize , state .dpi ).height
2761
2764
thickness = state .font_output .get_underline_thickness (
2762
2765
state .font , state .fontsize , state .dpi )
2763
2766
@@ -2766,26 +2769,38 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den):
2766
2769
if style is not self ._MathStyle .DISPLAYSTYLE :
2767
2770
num .shrink ()
2768
2771
den .shrink ()
2772
+ min_clearance = np .ceil (0.5 * thickness )
2773
+ cap_height *= 0.7
2774
+ else :
2775
+ min_clearance = 1.5 * thickness
2769
2776
cnum = HCentered ([num ])
2770
2777
cden = HCentered ([den ])
2771
2778
width = max (num .width , den .width )
2772
2779
cnum .hpack (width , 'exactly' )
2773
2780
cden .hpack (width , 'exactly' )
2774
- vlist = Vlist ([cnum , # numerator
2775
- Vbox (0 , thickness * 2.0 ), # space
2776
- Hrule (state , rule ), # rule
2777
- Vbox (0 , thickness * 2.0 ), # space
2778
- cden # denominator
2779
- ])
2781
+
2782
+ numerator_padding = max (
2783
+ 3 / 5 * cap_height - cnum .depth , min_clearance ) - thickness
2784
+ denominator_padding = max (
2785
+ 4 / 3 * cap_height - cden .height , min_clearance ) + thickness
2786
+ vlist_builder = []
2787
+ if cnum .height < cap_height :
2788
+ vlist_builder .append (Vbox (0 , cap_height - cnum .height ))
2789
+ vlist_builder += [cnum , # numerator
2790
+ Vbox (0 , numerator_padding ), # space
2791
+ Hrule (state , rule ), # rule
2792
+ Vbox (0 , denominator_padding ), # space
2793
+ cden # denominator
2794
+ ]
2795
+ vlist = Vlist (vlist_builder )
2780
2796
2781
2797
# Shift so the fraction line sits in the middle of the
2782
- # equals sign
2798
+ # minus sign
2783
2799
metrics = state .font_output .get_metrics (
2784
2800
state .font , mpl .rcParams ['mathtext.default' ],
2785
- '=' , state .fontsize , state .dpi )
2786
- shift = (cden .height -
2787
- ((metrics .ymax + metrics .ymin ) / 2 -
2788
- thickness * 3.0 ))
2801
+ '\u2212 ' , state .fontsize , state .dpi )
2802
+ shift = (denominator_padding + cden .height -
2803
+ (metrics .ymax + metrics .ymin ) / 2 - rule / 2 )
2789
2804
vlist .shift_amount = shift
2790
2805
2791
2806
result = [Hlist ([vlist , Hbox (thickness * 2. )])]
0 commit comments