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

Code before:
    num1: T.ClassVar[float] = 1.4

    # Percentage of x-height the numerator is shifted up in text, script and
    # scriptscript styles if there is a fraction line.
    num2: T.ClassVar[float] = 1.5

    # Percentage of x-height the numerator is shifted up in text, script and
    # scriptscript styles if there is no fraction line.
    num3: T.ClassVar[float] = 1.3

    # Percentage of x-height the denominator is shifted down in display style.
    denom1: T.ClassVar[float] = 1.3

    # Percentage of x-height the denominator is shifted down in text, script
    # and scriptscript styles.
    denom2: T.ClassVar[float] = 1.1


class ComputerModernFontConstants(FontConstantsBase):
    # Previously, the x-height of Computer Modern was obtained from the font
    # table. However, that x-height was greater than the the actual (rendered)
    # x-height by a factor of 1.771484375 (at font size 12, DPI 100 and hinting
    # type 32). Now that we're using the rendered x-height, some font constants
    # have been increased by the same factor to compensate.
    script_space = 0.132861328125
    supdrop = 0.386108 / 0.430555
    subdrop = 0.05 / 0.430555
    sup1 = 0.412892 / 0.430555
    sub1 = 0.15 / 0.430555
    sub2 = 0.247217 / 0.430555
    delta = 0.132861328125
    delta_slanted = 0.3
    delta_integral = 0.3
    num1 = 1.5
    num2 = 1.5
    num3 = 1.5
    denom1 = 1.6
    denom2 = 1.2


class STIXFontConstants(FontConstantsBase):
    script_space = 0.1
    sup1 = 0.8
    sub2 = 0.6
    delta = 0.05
    delta_slanted = 0.3
    delta_integral = 0.3
    num1 = 1.6
    num2 = 1.6
    num3 = 1.6
    denom1 = 1.6

Review comment (bug):
You can get more accurate (effectively fixed-point representation) values from the tfm file, as tftopl prints values after scaling and drops some decimal points, e.g. for cmsy10 I get
`
slant=262144, space=0, space_stretch=0, space_shrink=0, x_height=451470, quad=1048579, extra_space=0
num1=709370, num2=412858, num3=465286, denom1=719272, denom2=361592, sup1=432949, sup2=380520, sup3=302922, sub1=157286, sub2=259226, supdrop=404864, subdrop=52429, delim1=2506096, delim2=1059062, axis_height=262144
`
(values need to be scaled by `2**20`).

I extended the Tfm class to read these values at https://github.com/anntzer/matplotlib/commit/a360989b0e7c386b84e114e867f336f9105a7c44 if you want to try your hand at it (we don't need to decide now whether we actually want to integrate this functionality into the Tfm class).

Note that this also allows reading the actual definition of 1em and 1ex ("quad" and "x_height"), which should be better than the current approach of trying to guess the values (see @tfpf's comment
> I reported this as a bug back then (https://github.com/matplotlib/matplotlib/issues/23474). Changing the script rendering logic is what exposed it. After merging a fix (https://github.com/matplotlib/matplotlib/pull/23482), the test passed even with the updated logic.

the linked threads (https://github.com/matplotlib/matplotlib/issues/23474#issuecomment-1192976607), and https://tex.stackexchange.com/a/98139).
Perhaps also worth fixing this properly?

Code after:
    # Percentage of x-height that sub/superscripts are offset relative to the
    # nucleus edge for non-slanted nuclei
    delta: T.ClassVar[float] = 0.025

    # Additional percentage of last character height above 2/3 of the
    # x-height that superscripts are offset relative to the subscript
    # for slanted nuclei
    delta_slanted: T.ClassVar[float] = 0.2

    # Percentage of x-height that superscripts and subscripts are offset for
    # integrals
    delta_integral: T.ClassVar[float] = 0.1

    # Percentage of x-height the numerator is shifted up in display style.
    num1: T.ClassVar[float] = 1.4

    # Percentage of x-height the numerator is shifted up in text, script and
    # scriptscript styles if there is a fraction line.
    num2: T.ClassVar[float] = 1.5

    # Percentage of x-height the numerator is shifted up in text, script and
    # scriptscript styles if there is no fraction line.
    num3: T.ClassVar[float] = 1.3

    # Percentage of x-height the denominator is shifted down in display style.
    denom1: T.ClassVar[float] = 1.3

    # Percentage of x-height the denominator is shifted down in text, script
    # and scriptscript styles.
    denom2: T.ClassVar[float] = 1.1


class ComputerModernFontConstants(FontConstantsBase):
    # Previously, the x-height of Computer Modern was obtained from the font
    # table. However, that x-height was greater than the the actual (rendered)
    # x-height by a factor of 1.771484375 (at font size 12, DPI 100 and hinting
    # type 32). Now that we're using the rendered x-height, some font constants
    # have been increased by the same factor to compensate.
    script_space = 0.132861328125
    delta = 0.132861328125
    delta_slanted = 0.3
    delta_integral = 0.3
    _x_height = 451470
    # These all come from the cmsy10.tfm metrics, divided by the design xheight from
    # there, since we multiply these values by the scaled xheight later.
    supdrop = 404864 / _x_height
    subdrop = 52429 / _x_height
    sup1 = 432949 / _x_height
    sub1 = 157286 / _x_height
    sub2 = 259226 / _x_height
    num1 = 709370 / _x_height