# Customized root

At the moment I am quite dissatisfied with the root symbol provided by LaTex. The grievances I have against it are:

• it comsumes a lot of space
• the ceiling is too high
• n-th roots look aweful, especially if n is something even just a little more complicated than a single symbol
• The indication where the root ends isn't clear enough (especially bad when you have something like $\sqrt(...)i$)

For the last point already a few solutions exist, e.g. closed radical, but which also adds quite a bit of uneccessary whitespace behind the radicand.

Below is a crude paint edit of what I would fancy. Sadly my knowledge of how to customize core Tex stuff is pretty limit. Any help on how to do this would be greatly appreciated, even if it is just a reference to some tutorial on how to accomplish these sorts of things.

So basically I would want the basic sqrt to look likethe rightmost image. And when the optional argument of the index of the root is given there should be a small 'plateau' where it neatly sits on.

• – Steven B. Segletes Nov 30 '16 at 11:40
• Welcome to TeX - LaTeX! An central part of this would be creating/finding a font with usable glyphs. – Andrew Swann Nov 30 '16 at 11:40
• The various symbols for the square root are taken from the “math extension font”. You need a new font with all the symbols you need; not a task I would undertake. – egreg Nov 30 '16 at 12:03
• That sounds rather complicated. To be honest my hope was that one could simply define it more or less like this: Command \root input #1, optional input #2: Place input #1 at text-level and draw the 4 line segments that make up the root symbol. IF #2 is empty => done ELSE draw additional line segment (the 'plateau') and place #2 on top of in it in superscript-size – Hyperplane Nov 30 '16 at 12:31

In ConTeXt, it is possible to draw the root using Metapost. In the code below, I basically define a new radical alternative called hyperloop, which places the body and the radical of the square root as the appropriate place and then draws the lines. The output is not an exact match of what you had drawn by hand, but is close. Of course, you can tweak the definition of math_radical_hyperloop to change the shape, as desired.

First, the metapost code to draw the root:

\startMPextensions
(-h/3-max(r-o,o),h/3-o) --
(-h/3-o,h/3-o) --
(-o,-d-o)  --
(o,h+o)       --
(w+o,h+o)      --
(w+o,h-h/8+o)
enddef ;
\stopMPextensions


Next, we define a uniqueMP graphic that draws the root:

\startMPextensions
(-h/3-max(r-o,o),h/3-o) --
(-h/3-o,h/3-o) --
(-o,-d-o)  --
(o,h+o)       --
(w+o,h+o)      --
(w+o,h-h/8+o)
enddef ;
\stopMPextensions


and finally we define a math radical alternative:

\newbox\radicalbox

{\begingroup
\setbox\nextbox\mathstylehbox{#1}%
%
\scratchtopoffset   \dimexpr\scratchoffset+\dp\nextbox\relax
\scratchbottomoffset\dimexpr\ht\nextbox/3\relax
% we use the \overlay variables as these are passes anyway and
% it's more efficient than using parameters
\d_overlay_width    \wd\nextbox
\d_overlay_height   \ht\nextbox
\d_overlay_depth    \dp\nextbox
\d_overlay_offset   \scratchoffset
\d_overlay_linewidth\linewidth
%
%
\setbox\scratchbox\hpack\bgroup
\uniqueMPgraphic
{\p_mp}%
\egroup
\scratchdimen       \wd\scratchbox
\hpack to \scratchdimen{\hss\box\nextbox\hskip\scratchoffset}%
\hskip-\scratchdimen
\lower\dimexpr\scratchtopoffset\box\scratchbox%
\hskip-\scratchdimen
\fi

\endgroup}


This can be used as follows:

\definemathradical[sqrt][alternative=hyperplane, mp=math:radical:hyperplane,
color=red]

\starttext

$\sqrt{X} \sqrt[3]{X} \sqrt[2^n]{X}$

\stoptext


which gives

Here is the complete code:

\startMPextensions
(-h/3-max(r-o,o),h/3-o) --
(-h/3-o,h/3-o) --
(-o,-d-o)  --
(o,h+o)       --
(w+o,h+o)      --
(w+o,h-h/8+o)
enddef ;
\stopMPextensions

draw
withpen pencircle xscaled (2overlaylinewidth) yscaled (3overlaylinewidth/4) rotated 30
% dashed evenly
withcolor overlaylinecolor ;
\stopuniquempgraphic

{\begingroup
\setbox\nextbox\mathstylehbox{#1}%
%
\scratchtopoffset   \dimexpr\scratchoffset+\dp\nextbox\relax
\scratchbottomoffset\dimexpr\ht\nextbox/3\relax
% we use the \overlay variables as these are passes anyway and
% it's more efficient than using parameters
\d_overlay_width    \wd\nextbox
\d_overlay_height   \ht\nextbox
\d_overlay_depth    \dp\nextbox
\d_overlay_offset   \scratchoffset
\d_overlay_linewidth\linewidth
%
%
\setbox\scratchbox\hpack\bgroup
\uniqueMPgraphic
{\p_mp}%
\egroup
\scratchdimen       \wd\scratchbox
\hpack to \scratchdimen{\hss\box\nextbox\hskip\scratchoffset}%
\hskip-\scratchdimen
\lower\dimexpr\scratchtopoffset\box\scratchbox%
\hskip-\scratchdimen
\fi

\endgroup}

$\sqrt{X} \sqrt[3]{X} \sqrt[2^n]{X}$