[Tex/LaTex] Bad spacing of exponents in denominator


Please look at the following code:






x^{2} / x^{2}


Can you see the wrong placement of the exponent in the denominator? Compare it to the flat fraction.

output of example code

I do not really have an idea what to do to get the same spacing. Any suggestions?


Best Answer

Before reading on, please see this answer. What follows is about modifying TeX’s behavior so to obtain the desired output at the primitive level (in particular, not just for fractions, but for all occurences of a “cramped” style).

It is true what @Mico says in his comment, that is, that cramped style for denominators is a very low-level feature built into all TeX engines; but it is also true that it can be configured by means of the relevant \fontdimen parameters (so that I wouldn’t describe it as being “hard-wired”). The exact meaning of these parameters is defined in Appendix G of The TeXbook; in particular, what is relevant for this question is just the second sentence of Rule 18c (last two lines on p. 445), which dictates how TeX chooses the amount by which “ordinary” exponents (that is, not too deep) are to be raised when applied to “ordinary” base symbols (for example, single characters, as opposed to subformulas). It turns out that there are three possibilities:

  • in \displaystyle, the chosen amount is the value of the parameter that can be referred to as \fontdimen 13 \textfont 2;

  • in any “uncramped”, non-display style, the chosen amount is the value of \fontdimen 14 \<style>font 2

  • in any “cramped” (either display or non-display) style, the chosen amount is \fontdimen 15 \<style>font 2, except that <style> is substituted with text if it is display.

As it has already been pointed out by others, “cramped” styles are used for denominators of fractions; note, though, that they are used also in radicals, in \overline constructions, and still in other places.

As a consequence, it is possible to “disable”, virtually, the “cramped” styles simply by assigning to the 15th \fontdimen parameter the value of the 14th, thereby rising exponents in denominators by the same amount that TeX ordinarily uses for exponents in numerators; that is, exactly the opposite of what @Mico’s solution, which forces a “cramped” style in the numerators too, does.

However, there are some caveats.

  1. First of all, changes to \fontdimen parameters do not obey TeX grouping rules: their scope is always global (The TeXbook, p. 277). This means that, if you want to undo them, you need to save the original values “by hand”.

  2. In the second place, each \fontdimen change should be repeated thrice (once for each style, that is, for \textfont 2, \scriptfont 2, and \scriptscript 2), unless you want to disable “crampedness” only for some styles but not for others: for example, in order to disable “crampedness” only for \textstyle and \scriptstyle, but not for \scriptscriptstyle, you would change \fontdimen 15 \textfont 2 and \fontdimen 15 \scriptfont 2, but not \fontdimen 15 \scriptscriptfont 2.

  3. This triple setting, in turn, must be repeated for all the sizes (\normalsize, \footnotesize, …) at which you are typesetting formulas, since, in general, the font that corresponds to, say, \textfont 2 in \normalsize is not the same one that corresponds to \textfont 2 in \footnotesize.

  4. If you decide to suppress “crampedness”, it seems wise to suppress “displayedness” too, that is, to give the same value as \fontdimen 14 to \fontdimen 13 as well (see above).

The following code gives a sort of “proof of concept”. It defines two declarations, both of which are irreversible:

  • \LeveledExponentsForCurrentSize suppresses both “crampedness” and “displayedness” for the current font size only (but all the way to \scriptscriptstyle);

  • \LeveledExponentsForAllSizessuppresses both “crampedness” and “displayedness” for all the standard LaTeX sizes; note, however, that this will load a large number of math fonts, most of which you are never going to use, and which might cause you to hit the limit for the number of loadable fonts in certain engines (mainly, in pdfTeX).

As already hinted, the code makes no provision for saving the original values, and hence for reverting to the original setting. This isn’t difficult to accomplish, however.

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.


    \fontdimen 13 #1\tw@ \fontdimen 14 #1\tw@
    \fontdimen 15 #1\tw@ \fontdimen 14 #1\tw@
        #1% set font size
        \setbox\z@ \hbox{$$}% activate math font for that size
        \@level@exponents@for@font \textfont
        \@level@exponents@for@font \scriptfont
        \@level@exponents@for@font \scriptscriptfont
    \@level@exponents@for@size \@currsize
    \@level@exponents@for@size \tiny
    \@level@exponents@for@size \scriptsize
    \@level@exponents@for@size \footnotesize
    \@level@exponents@for@size \small
    \@level@exponents@for@size \normalsize
    \@level@exponents@for@size \large
    \@level@exponents@for@size \Large
    \@level@exponents@for@size \LARGE
    \@level@exponents@for@size \huge
    \@level@exponents@for@size \Huge



Compare $x^{2}$ with $\overline{x^{2}}$.
In display, three placements are possible:
\[x^{2}|{\textstyle x^{2}}|\overline{x^{2}}\]

As @Mico suggests, let's show fractions too, both in display, as in
\[\frac{x^{2}}{x^{2}}\ne x^{2},\]
and inline: \( \frac{x^{2}}{x^{2}}\ne x^{2} \).


Now compare them again: \( x^{2}|\overline{x^{2}} \).
Now in display:
\[x^{2}|{\textstyle x^{2}}|\overline{x^{2}}\]
And the fractions, displayed
\[\frac{x^{2}}{x^{2}}\ne x^{2},\]
and inline: \( \frac{x^{2}}{x^{2}}\ne x^{2} \).


For your convenience, here is the resulting output:

Output of the above code

Related Question