@@ -2759,6 +2759,9 @@ def subsuper(self, s, loc, toks):
27592759
27602760 def _genfrac (self , ldelim , rdelim , rule , style , num , den ):
27612761 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
27622765 thickness = state .font_output .get_underline_thickness (
27632766 state .font , state .fontsize , state .dpi )
27642767
@@ -2767,26 +2770,38 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den):
27672770 if style is not self ._MathStyle .DISPLAYSTYLE :
27682771 num .shrink ()
27692772 den .shrink ()
2773+ min_clearance = np .ceil (0.5 * thickness )
2774+ cap_height *= 0.7
2775+ else :
2776+ min_clearance = 1.5 * thickness
27702777 cnum = HCentered ([num ])
27712778 cden = HCentered ([den ])
27722779 width = max (num .width , den .width )
27732780 cnum .hpack (width , 'exactly' )
27742781 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 )
27812797
27822798 # Shift so the fraction line sits in the middle of the
2783- # equals sign
2799+ # minus sign
27842800 metrics = state .font_output .get_metrics (
27852801 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 )
27902805 vlist .shift_amount = shift
27912806
27922807 result = [Hlist ([vlist , Hbox (thickness * 2. )])]
0 commit comments