[Tex/LaTex] Superscripts appear in various weird places in fractions

fractionsmath-modesuperscripts

This is a weird phenomenon.

Consider the following code:

\documentclass{article}
\begin{document}
  $$Z^* \frac{Z^*}{Z^*}$$
\end{document}

It produces the following picture:

enter image description here

The asterisks appear in various places in comparison to the Z. This looks particularly bad in the denominator. Any idea what's behind this?

Best Answer

There's nothing weird about the placement of the three superscript asterisks. They are placed at different heights because they occur in three distinct math styles. (Aside: TeX has 8 possible math styles. See p. 140f. in the TeXbook for more information about these 8 styles.)

  • in the first term, TeX is in (uncramped) display style, labelled D in the TeXbook;

  • in the numerator term, TeX is in (un-cramped) text style, labelled T in the TeXbook; and

  • in the denominator term, TeX is in cramped text style, labelled T' in the TeXbook.

I assume you like the first look the best. If that's the case, you could write

\[ Z^* \frac{\displaystyle Z^*}{\displaystyle Z^*} \]

to force all three Z^* terms to have the same look.

Alternatively, you could set up a macro named, say, \ddfrac, as follows:

\newcommand\ddfrac[2]{\frac{\displaystyle #1}{\displaystyle #2}}

and then write

\[ Z^* \ddfrac{Z^*}{Z^*} \]

in the body of the text.

A small MWE: the item on the left shows the result of your original code, and the item on the right shows the output when using the \ddfrac macro:

enter image description here

\documentclass{article}
\newcommand\ddfrac[2]{\frac{\displaystyle #1}{\displaystyle #2}}
\begin{document}
$\displaystyle 
Z^*\frac{Z^*}{Z^*} \quad Z^*\ddfrac{Z^*}{Z^*}$
\end{document}

Addendum, inspired by David Carlisle's comment: pdfLaTeX provides four directives related to math style: \displaystyle, \textstyle, \scriptstyle, and \scriptscriptstyle. (The code above uses only one of these directives -- \displaystyle.) If you happen to use LuaLaTeX, you could employ four additional style-related directives: \crampeddisplaystyle, \crampedtextstyle, \crampedscriptstyle, and \crampedscriptscriptstyle. E.g., if you wanted to impose the "cramped text style look" on the numerator term of \frac, you could define a new macro as follows -- "ct" stands for "cramped text style":

\newcommand\ctfrac[2]{\frac{\crampedtextstyle #1}{\crampedtextstyle #2}}

Second Addendum, prompted by @daleif's comment: The mathtools package provides a directive called \cramped, which typesets its argument in the cramped version of the applicable uncramped math style. Using the mathtools package, then, one would write the preceding \ctfrac macro as follows:

\newcommand\ctfrac[2]{\frac{\cramped[\textstyle]{#1}}{\cramped[\textstyle]{#2}}}