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

Code before:
            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:
        return self._genfrac(
            "", "", self.get_state().get_current_underline_thickness(),
            self._MathStyle.TEXTSTYLE, toks["num"], toks["den"])

    def dfrac(self, toks: ParseResults) -> T.Any:
        return self._genfrac(
            "", "", self.get_state().get_current_underline_thickness(),
            self._MathStyle.DISPLAYSTYLE, toks["num"], toks["den"])

    def binom(self, toks: ParseResults) -> T.Any:
        return self._genfrac(
            "(", ")", 0,
            self._MathStyle.TEXTSTYLE, toks["num"], toks["den"])

    def _genset(self, s: str, loc: int, toks: ParseResults) -> T.Any:
        annotation = toks["annotation"]
        body = toks["body"]
        thickness = self.get_state().get_current_underline_thickness()

        annotation.shrink()
        centered_annotation = HCentered([annotation])
        centered_body = HCentered([body])
        width = max(centered_annotation.width, centered_body.width)
        centered_annotation.hpack(width, 'exactly')

Review comment (suggestion):
Compared to #22852, I added the intermediate `delta` variable to align a bit more with the TeX book algorithm.

Code after:
        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
                           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  # The minimum clearance.
            else:
                num_shift_up = consts.num3 * x_height
                den_shift_down = consts.denom2 * x_height
                min_clr = 3 * thickness  # The minimum clearance.
            def_clr = (num_shift_up - cnum.depth) - (cden.height - den_shift_down)
            clr = max(def_clr, min_clr)
            vlist = Vlist([cnum,          # numerator
                           Vbox(0, clr),  # space
                           cden           # denominator