This is best done stepwise.
Step 0 - Notation and definitions
Any symbol fonts (ie font family 2 in TeX language) must have at least 22 parameters in three different "styles" in order for TeX to typeset a formula. The "styles" roughly can be grouped as "text" for "display style", "text style" and their cramped version (see TeXBook), "script" for "script style" (cramped and standard) and "scriptscript" (cramped and standard). The TeXBook describes extensively how to determine which style to use and how to determine the correct style switch from main formula to super/subscripts.
Anyway these parameters are called fontdimenZ where Z is the number (spanning from 1 to 22, as mentioned before) and will identify which parameter we will have to use.
Note: only family2 is used here and we're not concerned with family3 except in one case, which will be detailed later on explicitly
Now with the serious steps:
Step 1 - Determine the character-specific shift u
This is a quantity that is determined based on what the superscript is appended to. u is set to:
This means that a^2 will have an u = 0, while {(a}^2 won't, since the math list contains more than one character.
Step 2 - Determine the style based shift p
This parameter is taken straight from the current style typeset and is:
fontdimen13 if the formula is typeset in display style
fontdimen15 if the formula is set in a cramped style
fontdimen14 if the formula is set in any other styles.
Step 3 - Determine the ex-height based shift s
Being d the depth of the superscript box, this is simply d+(1/4)|fontdimen5|.
Step 4 - Find the height without a subscript k (to compute anyway)
If no subscript is present, the amount that the superscript will be shifted up will be k=max(u,p,s). Otherwise k will be computed the same way but will not be used yet.
Step 5 - Find the height with a subscript
This time it's needed a detour to fontfamily3, of which we will take r=fontdimen8, which represents the default rule thickness.
If the distance from the "tentative" upshifted character and the subscript is ≥4r then the upshift is valid and we're done. Otherwise the subscript will get moved down in order to ensure the 4r spacing is enforced, and the calculations proceed to step 5a.
Step 5a (not always done, see previous step) - Correction factor q
q=(4/5)|fontdimen5|-k+d. If this is greater than 0, then k=k+q and the subscript gets shifted up of the same quantity q. Everything is typeset.
Interconnections among parameters and other formula typesetting
Here I will briefly detail how the parameters are intertwined with the other formula typesetting calculations, in order to be able to use and adjust only the ones needed. Please mind that this disregards completely family 3 which must not be touched for this purpose, since its parameter is used very widely
fontdimen13, fontdimen14, fontdimen15, and fontdimen18 are specifically used in these calculations only and are in fact superscript parameters.
fontdimen5 represents the "x-height" and is thus widely used:
(1/4) |(fontdimen 5)| also takes part into determining the height of the radical rule in radicals (actually takes part in the minimum clearance that will be allowed between the radicand and the rule), and of course it determines the total Height (with capital H to disambiguate it from the normal height, ie, the "H" takes into account depth) of the radical symbol.
- In the Accent atoms, it represents the maximum height of an accent atom, used to place a kern after an accent atom.
$|^{2}{|}^{2}{\mathord |}^{2}{\mathclose |}^{2}$and look at how the exponent are placed. This, by the way, explains why$\mathclose\rvert^{2}\mathclose{\rvert}^{2}$exhibits the issue, but$\mathclose\vert^{2}\mathclose{\vert}^{2}$does not. — I’m afraid I’ll have to defer the other remarks to tomorrow… – GuM May 24 '17 at 23:10$|^{2}$, nor in${|}^{2}$, nor in${\mathord |}^{2}$a inner math list is generated, and Rule 17 receives an atom whose nucleus is “simply a symbol”; but in the case of${\mathclose |}^{2}$(or${\mathopen |}^{2}$, or${\mathbin |}^{2}$…) the inner list is not stripped off, and Rule 17 will process an atom having that list as its nucleus. But I repeat, it’s enough for tonight! – GuM May 24 '17 at 23:22$.^{2}\cdot^{2}x^{2}f^{2})^{2}\mathchar"0364^{2}$. – GuM May 27 '17 at 10:35$X^{.|}_{..}$versus$X^{.|}_{.|}$. – GuM May 27 '17 at 10:46