Uneven height when using superscript in frac
The problem is in the “i”, where the ascender is setting the overall height of the nucleus in \sin^2
.
You can fix this by smashing the “i”; however, this would create problems if you do \overline{\sin x}
; a solution is to add another phantom before the real operator. I add a \mathop
atom containing the phantom for the real name, followed by \!
so the thin space that TeX inserts between two consecutive \mathop
atoms is removed.
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newcommand{\sinname}{sin}% change here
\newcommand{\sin@name}{%
\smash{\operator@font\sinname}\vphantom{s}%
}
\DeclareRobustCommand{\sin}{%
\mathop{\vphantom{\operator@font\sinname}}\!%
\qopname\relax o{\sin@name}%
}
\makeatother
\begin{document}
\begin{gather*}
\frac{1}{\sin\theta}+\frac{1}{\sin\alpha}\ne
\frac{1}{\sin^2\theta}+\frac{1}{\sin^2\alpha}
\\
\frac{1}{\sin\theta}\frac{\partial}{\partial\theta}\ne
\frac{1}{\sin^2\theta}\frac{\partial^2}{\partial\theta^2}
\\
\sqrt{\sin\alpha}+\sqrt{\cos\alpha}
\\
\frac{1}{\sqrt{\sin\alpha}}+\frac{1}{\sqrt{\cos\alpha}}
\\
\overline{\sin\alpha}
\end{gather*}
\end{document}
Nothing's perfect in this world! You can see the third line has the square root sign at different heights. A possible solution for this would be redefining \cos
to have the same height as \sin
:
\DeclareRobustCommand{\cos}{%
\mathop{\vphantom{\operator@font\sinname}}\!%
\qopname\relax o{cos}%
}
Since some typographic traditions use a different tag for \sin
(it might be “sen”), I only provide \sinname
as it shouldn't be necessary for \cos
to have a changing name.
With this definition, the overline would be at the same level for \sin
and \cos
, which might or not be desired.
Obviously (;-) @egreg’s answer is great and goes right to the point, but it does have an infinitesimal drawback: a pervert who tried $\overline{\sin x}$
would get a surprise. Moreover, one could argue that the placement of the radical sign in $\sqrt{\sin x}$
is suboptimal.
The positioning of superscripts in math formulas is a very low-level feature of TeX, which is described, along with many other “intimate” details of math typesetting, in Appendix G of The TeXbook, to which you are referred for an explanation of the following solution.
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
% egreg's recipe:
\makeatletter
\DeclareRobustCommand{\sinname}{%
\smash{\operator@font sin}\vphantom{s}%
}
% ... but let us use a different name for the operator:
\newcommand{\ssin}{\qopname\relax o{\sinname}}
\makeatother
% Our recipe:
\setbox0 = \hbox{$$} % load math fonts
\fontdimen18\scriptfont2 = 3.78970pt % turns out to be just enough
\begin{document}
The downside in egreg's answer:
\[\sqrt{\sin x}+\sqrt{\ssin x} + \overline{\sin x}+\overline{\ssin x}\]
That's not fine.
But, with our correction, the exponent of the ``usual'' \verb|\sin| will not be
rised that much:
\[ \frac{1}{\cos^{2}x} + \frac{1}{\sin^{2}x} + \frac{1}{x^{2}} \]
For an explanation, see \textsl{The \TeX book}, Appendix~G, Rule~18a; the
relevant passage is ``set \( u\gets h-q \)\,\ldots\ where $q$\,\ldots\ [is] the
[value] of~$\sigma_{18}$\,\ldots\ in the font corresponding to
[style]~$C{\uparrow}$''. What we are doing is to increase~$q$. The amended
value of~$u$ will be subsequently used in Rule~18c to position the superscript.
\end{document}
Here’s the output:
Let us also magnify the crucial portion:
Of course, this solution could have drawbacks too: changing in this way a parameter that operate at so low a level of TeX might cause side-effects which are not evident at first sight.
You can adjust the amount of space left for denominators using font dimen 11,
\documentclass{article}
\sbox0{$1$}
\fontdimen11\textfont2=8pt
\begin{document}
\[
\frac{1}{\sin\vartheta}
\frac{1}{\sin^{2}\vartheta}
\]
\end{document}