mtpro2 SQRT with root index affect the subsequent spacing

Thanks to @JPi’s amazing eyesight, I was able to track down exactly the bug in the mtpro2 package. All credits goes to him/her.

@JPi’s solution suggests that the offsetting space is somehow the width of the root index. I confirm this is the case. The root index is placed inside a box called \rootbox. Here is how LaTeX defines its placement:

% From ltmath.dtx:
\def\r@@t#1#2{%
  \setbox\z@\hbox{$\m@th#1\sqrtsign{#2}$}%
  \dimen@\ht\z@ \advance\dimen@-\dp\z@
  \mkern5mu\raise.6\dimen@\copy\rootbox
  \mkern-10mu\box\z@}

which is the default, while mtpro2 does some similar things like:

% From mtpro2.dtx or mtpro2.sty
\def\R@@T#1#2{\setbox\z@\hbox{$\UPROOT@\z@\LEFTROOT@\z@\m@th#1\SQR@@T{#2}$}%
\dimen@\ht\z@\advance\dimen@-\dp\z@
\dimen@ii\dimen@
\setbox\tw@\hbox{$\m@th#1\mskip\UPROOT@ mu$}\advance\dimen@ii by1.667\wd\tw@
\setbox\tw@\hbox{$\m@th#1\mskip10mu$}%
\ifcase\SQcount@\advance\dimen@3\wd\tw@\or\advance\[email protected]\wd\tw@\or
\advance\dimen@\wd\tw@\fi
\mkern1mu\kern.13\dimen@\mkern-\LEFTROOT@ mu
\raise.5\dimen@ii\copy\rootbox % was .44
\mkern-1mu\kern-.13\dimen@\mkern\LEFTROOT@ mu\box\z@\kern-\wd\rootbox
\LEFTROOT\z@\UPROOT\z@}

Focusing on the overall structures, we see immediately that \R@@T has additional code of \kern-\wd\rootbox, which IMHO is utterly wrong. So here is my fix:

\documentclass{article}
\usepackage{newtxtext}
\usepackage{mtpro2}% lite or complete, does not matter here

\usepackage{etoolbox}
\makeatletter
\patchcmd\R@@T
  {\kern-\wd\rootbox} % search this within \R@@T
  {} % replace it with nothing
  {}{}
\makeatother

\begin{document}
\[ \sqrt[100]{1000000} = 1000 \quad \sqrt[3]{1000000} = 100 \]
\[ \SQRT[100]{1000000} = 1000 \quad \SQRT[3]{1000000} = 100 \]
\end{document}

sqrt

Note: \sqrt and \SQRT, by design, will produce slightly different results (as seen in the above picture). \SQRT is supposed to be used for really large formulae (hence the awkward root index placement). Please refrain from using \SQRT for small formulae.


Don't know exactly why this fixes the problem, but it seems to. ;-)

\documentclass{article}


\usepackage{mtpro2}
\usepackage{mathtools}

\newcommand{\SQRTFIX}[2][ ]{{\hphantom{\scriptscriptstyle{#1}}}\SQRT[\mathllap{#1}]{#2}}


\begin{document}

\[ \sqrt[100]{1000000} = 1000 \quad \sqrt[3]{1000000} = 100 \]

\[
 \SQRT[100]{1000000}  = 1000  \quad \SQRT[3]{1000000} = 100 
\]

\[
 \SQRTFIX[100]{1000000} =1000 \quad \SQRTFIX[3]{1000000} = 100 
 \]
\end{document}

enter image description here

The second image simply shows in the yellow box what the original $\SQRT$ does and in the blue box what $\SQRTFIX$ does.

enter image description here

Tags:

Spacing

Mtpro