Repository: matplotlib/matplotlib
File: lib/matplotlib/_mathtext.py (Python)

Code before:
            delta = rule / 2
            num_clr = max(num_shift_up - cnum.depth - axis_height - delta, min_clr)
            den_clr = max(axis_height - delta + den_shift_down - cden.height, min_clr)
            # Possible bug in fraction rendering. See GitHub PR 22852 comments.
            vlist = Vlist([cnum,                     # numerator
                           Vbox(0, num_clr - rule),  # space
                           Hrule(state, rule),       # rule
                           Vbox(0, den_clr + rule),  # space
                           cden                      # denominator
                           ])
            vlist.shift_amount = cden.height + den_clr + delta - axis_height

        # Align the fraction without a fraction line (node743, node744 and node745).
        else:
            if style is self._MathStyle.DISPLAYSTYLE:
                num_shift_up = consts.num1 * x_height
                den_shift_down = consts.denom1 * x_height
                min_clr = 7 * thickness
            else:
                num_shift_up = consts.num3 * x_height
                den_shift_down = consts.denom2 * x_height
                min_clr = 3 * thickness
            def_clr = num_shift_up - cnum.depth + den_shift_down - cden.height
            clr = max(def_clr, min_clr)
            vlist = Vlist([cnum,          # numerator
                           Vbox(0, clr),  # space
                           cden           # denominator
                           ])
            vlist.shift_amount = den_shift_down
            if def_clr < min_clr:
                vlist.shift_amount += (min_clr - def_clr) / 2

        result: list[Box | Char | str] = [Hlist([
            Hbox(thickness),
            vlist,
            Hbox(thickness)
        ])]
        if ldelim or rdelim:
            return self._auto_sized_delimiter(ldelim or ".", result, rdelim or ".")
        return result

    def style_literal(self, toks: ParseResults) -> T.Any:
        return self._MathStyle(int(toks["style_literal"]))

    def genfrac(self, toks: ParseResults) -> T.Any:
        return self._genfrac(
            toks.get("ldelim", ""), toks.get("rdelim", ""),
            toks["rulesize"], toks.get("style", self._MathStyle.TEXTSTYLE),
            toks["num"], toks["den"])

    def frac(self, toks: ParseResults) -> T.Any:

Review comment (refactor):
Doesn't axis_height also need to be shrunk here?  Again perhaps it makes sense to first shrink the font and then directly extract axis_height/x_height from the shrunk font?

Code after:
                    y])
                x.shift_amount = shift_down

        if not self.is_dropsub(last_char):
            x.width += consts.script_space * x_height

        # Do we need to add a space after the nucleus?
        # To find out, check the flag set by operatorname
        optional_spacing = ([self._make_space(self._space_widths[r'\,'])]
                            if self._needs_space_after_subsuper else [])
        self._needs_space_after_subsuper = False
        result = Hlist([nucleus, x, *optional_spacing])
        return [result]

    def _genfrac(self, ldelim: str, rdelim: str, rule: float | None, style: _MathStyle,
                 num: Hlist, den: Hlist) -> T.Any:
        state = self.get_state()
        thickness = state.get_current_underline_thickness()

        axis_height = state.fontset.get_axis_height(
            state.font, state.fontsize, state.dpi)
        consts = _get_font_constant_set(state)
        x_height = state.fontset.get_xheight(state.font, state.fontsize, state.dpi)

        for _ in range(style.value):
            x_height *= SHRINK_FACTOR
            num.shrink()
            den.shrink()
        cnum = HCentered([num])
        cden = HCentered([den])
        width = max(num.width, den.width)
        cnum.hpack(width, 'exactly')
        cden.hpack(width, 'exactly')

        # Align the fraction with a fraction line (node743, node744 and node746).
        if rule:
            if style is self._MathStyle.DISPLAYSTYLE:
                num_shift_up = consts.num1 * x_height
                den_shift_down = consts.denom1 * x_height
                clr = 3 * rule  # The minimum clearance.
            else:
                num_shift_up = consts.num2 * x_height
                den_shift_down = consts.denom2 * x_height
                clr = rule  # The minimum clearance.
            delta = rule / 2
            num_clr = max((num_shift_up - cnum.depth) - (axis_height + delta), clr)
            den_clr = max((axis_height - delta) - (cden.height - den_shift_down), clr)
            vlist = Vlist([cnum,                # numerator
                           Vbox(0, num_clr),    # space
                           Hrule(state, rule),  # rule
                           Vbox(0, den_clr),    # space