2

Following this question, and some support via chat, I decided to dig into the internals of subscripts (and possibly to continue the series further with at least radicals).

So the question is: how does TeX decide how much to shift down the subscripts? Also which font-related characteristics are used and how do they affect other formulas?

Moriambar
  • 11,466

1 Answers1

4

I will continue with the steps described in the question mentioned above.

I will report here the steps that are equal to the other answer in order to make this answer self-contained too.

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 v

This is a quantity that is determined based on what the superscript is appended to. v is set to:

  • 0 if we're appending the subscript to a single character,
  • 0 if the supposed "math list" (roughly a grouped set of math symbols) is composed by a single ordinary symbol with no sub or superscripts, other than an accent atom (the list is never actually made)
  • d+SUBfontdimen19 when it's appended to another type of math list (practically any other case), where:

    • d is the depth of the box constructed for the list
    • SUBfontdimen19 is the fontdimen19 for the style in which the subscript has to be set

This means that a_2 will have a v = 0, while {(a}_2 won't, since the math list contains more than one character.

Step 2 - Determine the ex-height based shift s

Calling h the height of the subscript, s=h-(4/5)|fontdimen5|

Step 3 - Determine the shift without superscript p

If no superscript are available, then the downshift is p=max(v,fontdimen16,s). This factor is calculated even for the next step

Step 4 - Subscript/superscript combination factor k

If a superscript is present, then a new tentative shift is calculated for the subscript: k=max(p,fontdimen17), then the calculation proceed further

Step 4a - Subscript/Superscript combination fine tuning

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" downshifted character and the superscript is ≥4r then the downshift is valid and we're done. Otherwise the downshift will be adjusted in order to obtained the 4r spacing, and the calculations proceed to step 4b.

Step 4b - Correction factor q

q=(4/5)|fontdimen5|-k+d. If this is greater than 0, then |k|=|k|+q and the superscript gets shifted up of the same quantity q. Everything is then 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

  • fontdimen16, fontdimen17, fontdimen19 are specifically used in these calculations only and are in fact subscript parameters.

  • fontdimen5 represents the "x-height" and is thus widely used:

    1. (1/4) |(fontdimen 5)| also takes part into dtermining 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.
    2. In the Accent atoms, it represents the maximum height of an accent atom, used to place a kern after an accent atom.
Moriambar
  • 11,466