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