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

Code before:
            if sub is not None:
                sub.shrink()
                width = max(width, sub.width)

            vgap = rule_thickness * 3.0
            if super is not None:
                hlist = HCentered([super])
                hlist.hpack(width, 'exactly')
                vlist.extend([hlist, Vbox(0, vgap)])
            hlist = HCentered([nucleus])
            hlist.hpack(width, 'exactly')
            vlist.append(hlist)
            if sub is not None:
                hlist = HCentered([sub])
                hlist.hpack(width, 'exactly')
                vlist.extend([Vbox(0, vgap), hlist])
                shift = hlist.height + vgap + nucleus.depth
            vlt = Vlist(vlist)
            vlt.shift_amount = shift
            result = Hlist([
                vlt,
                *([self._make_space(self._space_widths[r'\,'])]
                  if self._needs_space_after_subsuper else []),
            ])
            self._needs_space_after_subsuper = False
            return [result]

        # We remove kerning on the last character for consistency (otherwise
        # it will compute kerning based on non-shrunk characters and may put
        # them too close together when superscripted)
        # We change the width of the last character to match the advance to
        # consider some fonts with weird metrics: e.g. stix's f has a width of
        # 7.75 and a kerning of -4.0 for an advance of 3.72, and we want to put
        # the superscript at the advance
        last_char = nucleus
        if isinstance(nucleus, Hlist):
            new_children = nucleus.children
            if len(new_children):
                # remove last kern
                if (isinstance(new_children[-1], Kern) and
                        isinstance(new_children[-2], Char)):
                    new_children = new_children[:-1]
                last_char = new_children[-1]
                if isinstance(last_char, Char):
                    last_char.width = last_char._metrics.advance
            # create new Hlist without kerning
            nucleus = Hlist(new_children, do_kern=False)
        else:
            if isinstance(nucleus, Char):
                last_char.width = last_char._metrics.advance
            nucleus = Hlist([nucleus])

Review comment (suggestion):
Optional alternative spelling. Choose whichever you like.
```suggestion
            spacing_nodes = (
                [self._make_space(self._space_widths[r'\,'])]
                if self._needs_space_after_subsuper else []
            )
            self._needs_space_after_subsuper = False
            return [Hlist([vlt, *spacing_nodes])]
```

Code after:
                vlist.extend([Vbox(0, vgap), hlist])
                shift = hlist.height + vgap + nucleus.depth
            vlt = Vlist(vlist)
            vlt.shift_amount = shift
            optional_spacing = ([self._make_space(self._space_widths[r'\,'])]
                                if self._needs_space_after_subsuper else [])
            self._needs_space_after_subsuper = False
            result = Hlist([vlt, *optional_spacing])
            return [result]

        # We remove kerning on the last character for consistency (otherwise
        # it will compute kerning based on non-shrunk characters and may put
        # them too close together when superscripted)
        # We change the width of the last character to match the advance to
        # consider some fonts with weird metrics: e.g. stix's f has a width of
        # 7.75 and a kerning of -4.0 for an advance of 3.72, and we want to put
        # the superscript at the advance
        last_char = nucleus
        if isinstance(nucleus, Hlist):
            new_children = nucleus.children
            if len(new_children):
                # remove last kern
                if (isinstance(new_children[-1], Kern) and
                        isinstance(new_children[-2], Char)):
                    new_children = new_children[:-1]
                last_char = new_children[-1]
                if isinstance(last_char, Char):
                    last_char.width = last_char._metrics.advance
            # create new Hlist without kerning
            nucleus = Hlist(new_children, do_kern=False)
        else:
            if isinstance(nucleus, Char):
                last_char.width = last_char._metrics.advance
            nucleus = Hlist([nucleus])

        # Handle regular sub/superscripts
        consts = _get_font_constant_set(state)
        lc_height   = last_char.height
        lc_baseline = 0
        if self.is_dropsub(last_char):
            lc_baseline = last_char.depth

        # Compute kerning for sub and super
        superkern = consts.delta * x_height
        subkern = consts.delta * x_height
        if self.is_slanted(last_char):
            superkern += consts.delta * x_height
            superkern += consts.delta_slanted * (lc_height - x_height * 2 / 3)
            if self.is_dropsub(last_char):
                subkern = (3 * consts.delta - consts.delta_integral) * lc_height
                superkern = (3 * consts.delta + consts.delta_integral) * lc_height