6

I don't like how the wide mn index of the roots is being displayed and am looking to see how others have handled this problem. I am using the closed square root from the references listed below which allows me to tweak the locations slightly and hence am able to get the m and n aligned on the left hand side, and tried moving the indices on the right, but am not pleased with the result:

enter image description here

References:

Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}
\usepackage{letltxmacro}

\LetLtxMacro{\oldsqrt}{\sqrt}

\def\DHLhksqrt#1#2{%
  \setbox0=\hbox{$#1\oldsqrt{#2\,}$}\dimen0=\ht0\relax%
  \advance\dimen0-0.25\ht0\relax%
  \setbox2=\hbox{\kern-0.375pt\vrule height\ht0 depth -\dimen0}%
  {%
    \hbox{$#1\expandafter\oldsqrt\expandafter[\DHLindex]{#2\,}$}%
    \lower\ifx\math@version\bold@name0.60pt\else0.4pt\fi\box2%
  }%
}
\newcommand{\ClosedSqrt}[1][]{\def\DHLindex{#1}\mathpalette\DHLhksqrt}%

\RenewDocumentCommand{\sqrt}{O{\hphantom{3}} O{0} O{0}  m}{\ClosedSqrt[\leftroot{#2}\uproot{#3}#1]{#4}}%

\begin{document}
\begin{alignat*}{3}
    \oldsqrt[m]{\oldsqrt[n]{x}} &= \oldsqrt[mn]{x} &\quad\text{original sqrt}\\
    \sqrt[m][-3]{\sqrt[n][-1][2]{x}} &= \sqrt[mn]{x} = \sqrt[mn][-3][2]{x} &\quad\text{closed sqrt}
\end{alignat*}
\end{document}
5
  • 1
    definitely not an answer, but I quite like to use rational exponents when the index gets too unruly :)
    – cmhughes
    Jul 5, 2012 at 5:25
  • @cmhughes: Agreed, for general equations. But for the case where this radicals are being introduced to students, I think it is important to stick with radicals. Jul 5, 2012 at 5:57
  • The first example seems fine to me. Of course there's always $x^{1/(mn)}$. :)
    – egreg
    Jul 5, 2012 at 8:43
  • Since you already have amsmath loaded the \uproot and \leftroot commands can be used for adjusting the position of the indices by small amounts Jul 5, 2012 at 13:59
  • @DavidCarlisle: I am already doing that in the above as the redefined \sqrt accepts two additional parameters which make use of the up and left movement. Jul 5, 2012 at 16:25

1 Answer 1

3

This is what I can offer.

\documentclass{article}
\usepackage{amsmath,array}
\usepackage{xparse}
\usepackage{letltxmacro}

\LetLtxMacro{\latexsqrt}{\sqrt}

\ExplSyntaxOn
\RenewDocumentCommand{\sqrt}{ O{\hphantom{3}} O{0} O{0}  m }
 {
  \grill_root:nnxx 
   { #1 } % index
   { #4 } % main argument
   { \int_eval:n { #2 - 1 } } % left shift (default -1)
   { \int_eval:n { #3 + 1 } } % up shift (default 1)
 }
\cs_new_protected:Npn \grill_root:nnnn #1 #2 #3 #4
 {
  \latexsqrt[ \leftroot{#3} \uproot{#4} #1 ] { #2 }
 }
\cs_generate_variant:Nn \grill_root:nnnn { nnxx }
\ExplSyntaxOff

\begin{document}
\renewcommand{\arraystretch}{1.5}

\begin{tabular}{>{$\displaystyle}r<{$}@{}>{$\displaystyle{}}l<{$}}

\multicolumn{2}{l}{Original} \\
\latexsqrt[m]{\latexsqrt[n]{x}} &= \latexsqrt[mn]{x}\\
\latexsqrt[n]{\latexsqrt[m]{x}} &= \latexsqrt[nm]{x}\\
\latexsqrt[p]{\latexsqrt[q]{x}} &= \latexsqrt[pq]{x}\\

\multicolumn{2}{l}{New} \\
\sqrt[m]{\sqrt[n]{x}} &= \sqrt[mn]{x}\\
\sqrt[n]{\sqrt[m]{x}} &= \sqrt[nm]{x}\\
\sqrt[p]{\sqrt[q]{x}} &= \sqrt[pq]{x}

\end{tabular}
\end{document}

The renewed \sqrt command applies by default a \leftroot{-1} and a \uproot{1} to which the optional arguments add. This seems a good compromise in normal cases: an index with a descender doesn't touch the root symbol.

I'm afraid that something that works well with all sizes of the radical is impossible.

If you say

\sqrt[3][1][-1]

you clear off the default adjustment, but the optional arguments can be any integers.

Of course I won't consider the "closed" root, for reasons you should know. ;-)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.