2

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.

customized root

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.

  • 1
    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
  • 3
    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
4

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
    vardef math_radical_hyperplane(expr w,h,d,o,r) =
        (-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
    vardef math_radical_hyperplane(expr w,h,d,o,r) =
        (-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

\unprotected\setvalue{\??mathradicalalternative hyperplane}#1% 
  {\begingroup
   \setbox\nextbox\mathstylehbox{#1}%
   \setbox\radicalbox\mathstylehbox{\scriptscriptstyle\currentmathradicaldegree\hss}%
   %
   \scratchoffset      \mathradicalparameter\c!mpoffset
   \scratchtopoffset   \dimexpr\scratchoffset+\dp\nextbox\relax
   \scratchbottomoffset\dimexpr\ht\nextbox/3\relax
   \scratchleftoffset  \wd\radicalbox
   % 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
   \edef\overlaylinecolor{\mathradicalparameter\c!color}%
   %
   \edef\p_mp{\mathradicalparameter\c!mp}%
   %
   \setbox\scratchbox\hpack\bgroup 
     \uniqueMPgraphic
       {\p_mp}%
       {radical=\scratchleftoffset}%
   \egroup
   \scratchdimen       \wd\scratchbox
   \hpack to \scratchdimen{\hss\box\nextbox\hskip\scratchoffset}%
   \hskip-\scratchdimen
   \lower\dimexpr\scratchtopoffset\box\scratchbox%
   \ifx\currentmathradicaldegree\empty \else
     \wd\radicalbox\scratchdimen
     \hskip-\scratchdimen
     \raise\dimexpr\scratchbottomoffset\box\radicalbox
   \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

enter image description here

Here is the complete code:

\startMPextensions
    vardef math_radical_hyperplane(expr w,h,d,o,r) =
        (-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

\setupmpvariables[math:radical:hyperplane][radical=0pt]

\startuniquempgraphic{math:radical:hyperplane}{radical}
    draw
        math_radical_hyperplane(overlaywidth,overlayheight,overlaydepth,overlayoffset,\mpvar{radical})
        withpen pencircle xscaled (2overlaylinewidth) yscaled (3overlaylinewidth/4) rotated 30
      % dashed evenly
        withcolor overlaylinecolor ;
\stopuniquempgraphic

\newbox\radicalbox

\unprotected\setvalue{\??mathradicalalternative hyperplane}#1% 
  {\begingroup
   \setbox\nextbox\mathstylehbox{#1}%
   \setbox\radicalbox\mathstylehbox{\scriptscriptstyle\currentmathradicaldegree\hss}%
   %
   \scratchoffset      \mathradicalparameter\c!mpoffset
   \scratchtopoffset   \dimexpr\scratchoffset+\dp\nextbox\relax
   \scratchbottomoffset\dimexpr\ht\nextbox/3\relax
   \scratchleftoffset  \wd\radicalbox
   % 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
   \edef\overlaylinecolor{\mathradicalparameter\c!color}%
   %
   \edef\p_mp{\mathradicalparameter\c!mp}%
   %
   \setbox\scratchbox\hpack\bgroup 
     \uniqueMPgraphic
       {\p_mp}%
       {radical=\scratchleftoffset}%
   \egroup
   \scratchdimen       \wd\scratchbox
   \hpack to \scratchdimen{\hss\box\nextbox\hskip\scratchoffset}%
   \hskip-\scratchdimen
   \lower\dimexpr\scratchtopoffset\box\scratchbox%
   \ifx\currentmathradicaldegree\empty \else
     \wd\radicalbox\scratchdimen
     \hskip-\scratchdimen
     \raise\dimexpr\scratchbottomoffset\box\radicalbox
   \fi

   \endgroup}


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

\starttext

\startTEXpage[offset=3mm]
$ 
  \sqrt{X}
  \sqrt[3]{X}
  \sqrt[2^n]{X}
$
\stopTEXpage

\stoptext

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.