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