4

Please look at the following MWE. I found an automatic solution for nice roots. The depth of letters ist ignored and subscripts do not influence the depth.

But when I nest the roots, it gets ugly. What am I doing wrong? What has to be done for nice nested roots?

Thanks.

Sorry for using \over, but I usually use Plain (Lua-)TeX. But loading OTF fonts with low level commands would give many extra lines in the code, so I write this MWE with LuaLaTeX and Unicode Math.

% Only for LuaTeX
\documentclass[17pt]{extarticle}
\usepackage[math-style=upright]{unicode-math}
\setmainfont{lmroman10-regular.otf}
\setmathfont{latinmodern-math.otf}

\begin{document}

\makeatletter
\newbox\r@@tbox
\newdimen\r@dic@ldepth

% to get cramped style
\def\mathpalettecramped#1#2{\mathchoice{#1\crampeddisplaystyle{#2}}%
    {#1\crampedtextstyle{#2}}{#1\crampedscriptstyle{#2}}%
    {#1\crampedscriptscriptstyle{#2}}}

\protected\def\sqrt{\mathpalettecramped\printr@@t}

\def\printr@@t#1#2{\begingroup
    \Umathcodenum`j=`i % example for goobling depth of letters
    \setbox\z@\hbox{\scantokens{\catcode`\_=\active \let_=\@gobble
                    $\m@th#1{\vphantom{0}#2}$}} % Subscripts do not influence depth
    \global\r@dic@ldepth\dp\z@
    \endgroup
    \setbox\r@@tbox\hbox{$\m@th#1{\vphantom{0}#2}$}
    \dp\r@@tbox\r@dic@ldepth
    \Uradical"0"221A {\box\r@@tbox}}

\section{Good}
This works fine for not nested roots:
$ \sqrt A \sqrt j $, $ \sqrt{Aj} $, $ \sqrt{1_{1_1}\over Aj_{A_A}} $

\section{Bad}
However, there is a problem with nested roots:
$ \sqrt{\sqrt{\sqrt{\sqrt{\sqrt{11}}}}} $

The base of the root signs alternates and the radical rules
are vertically spaced unequal. What am I doing wrong?

\end{document}
  • 3
    ` \global` looks suspicious in anything that can be nested – David Carlisle Jul 16 at 22:33
6

If you avoid the global setting with

\expandafter\endgroup
\expandafter\r@dic@ldepth\the\dp\z@\relax

Then you get

enter image description here

  • Good answer. I'm putting this question in my favorites. Why does this happen with root boxes? I've also tried mtpro2[lite] and the same thing happens. – Sebastiano Jul 16 at 22:42
  • 2
    @Sebastiano it's nothing to do with roots, as I commented under the question anything using \global is likely to fail in a nested context as global definitions do not obey the nested scope. – David Carlisle Jul 16 at 22:44
  • Thank you, this is what I wanted. On this website I have already learned more about TeX than in every book. – user125730 Jul 18 at 13:53

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.