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 some horizontal displacement of the subscript that is determined by the italic correction of the character: for example, the subscript should be shifted to the left for anF
, but not for anA
.The default values for raising and lowering are as follows in the case of "simple characters". The superscript is (tentatively!) raised by the maximum of
(depth of superscript) + (1/4 of the x-height)
andσk
, where the x-height is the\fontdimen
parameter number 5, andσk
is\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 subscript is lowered depends on the presence of a superscript. If there's a superscript, then the subscript is (tentatively!) lowered by
σ17
, otherwise by the maximum of(height of subscript) - (80% of the x-height)
andσ16
. 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.If the sub- or superscript is not attached 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) - σ18
, the subscript is lowered by at least(depth of nucleus) + σ19
, whereσ18
andσ19
are to be taken from\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.