[Tex/LaTex] Vertical positioning of superscripts and subscripts in math mode

math-modepositioningsubscriptssuperscripts

The question can be found around but with no satisfactory answer. I want to position the subscript more down and superscript more up.

The code to test it on is simple:

$1.23_{-22.22}^{-1.23221}$

The major requirement, no phantom boxes and other ugly tricks should be used. The sub- and superscripts have to be written as suggested above. Further, I want to enable the "improved positioning" and then return to the standard positioning (I have a large table with the numbers as suggested above). There is a suggestion here. But the author does it only for subscripts and superscripts separately. For the case when both super and subscripts are used, he refers to the tex book appendix G, I tried to look at it, but I do not really have no idea how to connect the ideas, I am the latex user not developer. The mentioned text also provides a good example how I would like the super and sub scripts to look like. Also, I would like the superscript and subscript to be left aligned with each other if that is possible.

Best Answer

Your referenced article alters \fontdimen14 for superscripts and \fontdimen16 for subscripts.

You need to alter \fontdimen17 as well, for the case of simultaneous super and subscripts (note: \textfont2 works for display and text math styles only. For the script and scriptscript styles, use \scriptfont2 and \scriptscriptfont2, respectively).

Furthermore, if you wish to retain the higher superscript in cramped modes like under a radical, you need to also alter \fontdimen15.

\documentclass[10pt]{article}
\begin{document}
$1.23_{-22.22}^{-1.23221}$
$
\fontdimen14\textfont2=6pt
\fontdimen15\textfont2=6pt
\fontdimen16\textfont2=5pt
\fontdimen17\textfont2=5pt
1.23_{-22.22}^{-1.23221}
1.23_{-22.22}
1.23^{-1.23221}
\sqrt{1.23^{-1.23221}}$
\end{document}

enter image description here

To have these \fontdimens set temporarily, one should save the original values and restore them as desired.


Here is how it might be done, across font sizes, with switchback to original dimensions:

\documentclass{article}
\setbox0=\hbox{$%
\xdef\fdfourteen{\the\fontdimen14\textfont2}
\xdef\fdfifteen{\the\fontdimen15\textfont2}
\xdef\fdsixteen{\the\fontdimen16\textfont2}
\xdef\fdseventeen{\the\fontdimen17\textfont2}
$}
\newcommand\newss{\setbox0=\hbox{\(\)}%
\fontdimen14\textfont2=1.5ex
\fontdimen15\textfont2=1.5ex
\fontdimen16\textfont2=1.1ex
\fontdimen17\textfont2=1.1ex
}
\newcommand\origss{\setbox0=\hbox{\(\)}%
\fontdimen14\textfont2=\fdfourteen%
\fontdimen15\textfont2=\fdfifteen%
\fontdimen16\textfont2=\fdsixteen%
\fontdimen17\textfont2=\fdseventeen%
}
\parskip=1em% FOR THIS MWE ONLY
\def\test{$
  1.23_{-22.22}^{-1.23221}\quad
  1.23_{-22.22}\quad
  1.23^{-1.23221}\quad
  \sqrt{1.23^{-1.23221}}
$}
\begin{document}
\fdfourteen, \fdfifteen, \fdsixteen, \fdseventeen

\origss Orig: \test\par{\footnotesize Orig(footnotesize): \test}

\newss New: \test\par{\footnotesize\newss New(footnotesize): \test}

\origss Orig: \test\par{\footnotesize\origss Orig(footnotesize): \test}
\end{document}

enter image description here

Related Question