I'm trying to define a set of commands for superscript and subscript, but cannot use the characters `^`

and `_`

in doing so. I've been able to define the correct font size by using `\check@mathfonts\fontsize\sf@size\z@\math@fontsfalse\selectfont`

, but can not work out the default values for how much the text box is raised and lowered.

How does TeX/LaTeX define these values?

## Best Answer

The algorithm for placing sub- and superscripts is "hard-wired" in the TeX engine, and it's not as simple as you might think. First of all, there's a special treatment for sub- and superscripts of "simple characters" like

`a`

,`\alpha`

or`\mathcal{A}`

. In this case you also have somehorizontaldisplacement of the subscript that is determined by the italic correction of the character: for example, the subscript should be shifted to the left for an`F`

, but not for an`A`

.The default values for raising and lowering are as follows in the case of "simple characters". The

superscriptis (tentatively!) raised by the maximum of`(depth of superscript) + (1/4 of the x-height)`

and`σ`

, where the x-height is the_{k}`\fontdimen`

parameter number 5, and`σ`

is_{k}`\fontdimen`

parameter number k (of`\textfont2`

unless the whole formula is in a sub- or superscript itself). Now it depends on the current style (which, unfortunately, the TeX user can only access via`\mathpalette`

or`\mathchoice`

): In`\displaystyle`

k=13 is used, in "cramped style" k=15, and k=14 otherwise.How much the

subscriptis lowered depends on the presence of a superscript. If there's a superscript, then the subscript is (tentatively!) lowered by`σ`

, otherwise by the maximum of_{17}`(height of subscript) - (80% of the x-height)`

and`σ`

. In the case of a sub- and superscript combination there's an additional adjustment (with some unpleasant side effects), see e.g. this answer of mine._{16}If the sub- or superscript is

notattached to a "simple character" but to some other nucleus, then additional minimum shift values are used: the superscript is raised by at least`(height of nucleus) - σ`

, the subscript is lowered by at least_{18}`(depth of nucleus) + σ`

, where_{19}`σ`

and_{18}`σ`

are to be taken from_{19}`\scriptfont2`

unless the whole formula is in a sub- or superscript itself (in which case`\scriptscriptfont2`

should be used).I'm not sure if you really want to implement this ... if you do, have a look at Rule 18 of Appendix G in the TeXbook for details.