[Tex/LaTex] “Closed” (square) root symbol


I found a cool trick in the LaTeX wikibook which allows the square root sign to be altered such that it "closes" over its contents.
Here's an example:

closed root

("closed" root on the left, normal one on the right)

The way they do this is as follows:

% New definition of square root:
% it renames \sqrt as \oldsqrt
% it defines the new \sqrt in terms of the old one
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%

The cool thing is that (as far as I've tested it) this works regardless of the math font and with pdftex as well as xetex.
However what is not possible is mulitple roots, such as \sqrt[3]{a}. Those produce incorrect output when this "trick" is being used.

So my question is, is somebody able to tweak this code so that it works for multiple roots as well?

Best Answer

Here's an example redefining the internal macro \r@@t of latex.ltx:

\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%
\renewcommand*{\sqrt}[2][\ ]{\oldsqrt[#1]{#2}}
\[ \sqrt[3]{\frac{a}{b}} \quad \sqrt{\frac{a}{b}} \]

cubic and normal roots

Edit: \LetLtxMacro{\oldsqrt}{\sqrt} instead of \let\oldsqrt\sqrt because \sqrt takes an optional argument (as advised by egreg)