Closed root symbols

handwritten closed square root
In LaTeX/Mathematics, Wikipedia writes:

Some people prefer writing the square root “closing” it over its content. This method arguably makes it more clear just what is in the scope of the root sign.

It shows a solution defining \sqrt in terms of the default one, which works well. However, Wikipedia continues:

Unfortunately this code won’t work if you want to use multiple roots: if you try to write \sqrt[b]{a} … you’ll just get a wrong output. In other words, you can redefine the square root this way only if you are not going to use multiple roots in the whole document.

handwritten roots
On TeX.SX Matthias posted the question, how to solve this for roots of arbitrary degree. I had a look into latex.ltx and decided to redefine the internet \r@@t macro, still similar to the Wikipedia solution:

\makeatletter
\let\oldr@@t\r@@t
\def\r@@t#1#2{%
\setbox0=\hbox{$\oldr@@t#1{#2\,}$}\dimen0=\ht0
\advance\dimen0-0.2\ht0
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%
{\box0\lower0.4pt\box2}}
\LetLtxMacro{\oldsqrt}{\sqrt}
\renewcommand*{\sqrt}[2][]{\oldsqrt[#1]{#2}}
\makeatother

Now we get a closed root symbol for example also for cubic roots. However, roots without optional arguments, i.e. are not closed. Finally, this can be fixed by forcing \sqrt using the optional argument, if necessary just using a space because. An empty optional argument would cause wrong spacing.

\usepackage{letltxmacro}
\LetLtxMacro{\oldsqrt}{\sqrt}
\renewcommand*{\sqrt}[2][\ ]{\oldsqrt[#1]{#2}}

Here we did not use TeX’s \let command, but the letltxmacro package which works safer for LaTeX macros with optional arguments. See complete source example. Output:

Rlosed roots

Matthias wrote a suggestion for incorporating the solution on the Wikipedia discussion page.

This was originally discussed on TeX.SX: “Closed” (square) root symbol.

02. October 2011 by stefan
Categories: Mathematics | Leave a comment

Leave a Reply