This is comparable to the problem of bundling several key-value arguments (for instance for \includegraphics
) in a macro: At the time of executing (the amsmath version of) \sqrt
, which is now \OldSqrt
, the content of []
is parsed for \leftroot
&c. At that time only \DHLindex
is found, and later \leftroot
is useless.
Changing
\setbox0=\hbox{$#1\OldSqrt[\DHLindex]{#2\,}$}\dimen0=\ht0\relax%
to
\setbox0=\hbox{$#1\expandafter\OldSqrt\expandafter[\DHLindex]{#2\,}$}\dimen0=\ht0\relax%
makes the \leftroot
visible and the first attempt goes through.
Dunno whether it does what you want though.
This should also work for attempt 2. Didn't look at attempt 3.
EDIT: What exactly do you want to know about the \DHLhksqrt
macro? AFAICS it takes two arguments, builds a root expression from them, which it measures and tries (with debatable success) to decorate with an additional vertical rule.
EDIT2: To make this look a bit better, at least \DHLhksqrt
needs to take into account when the root index is moved above the root symbol, otherwise the additional rule is placed too high.
EDIT3: Ok, here's my take at a correction for the displacement problem. The root is formatted twice, so there might be a performance problem.
\def\DHLhksqrt#1#2{%
\setbox0=\hbox{$#1\OldSqrt{#2\,}$}\dimen0=\ht0\relax%
\advance\dimen0-0.2\ht0\relax%
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%
{\hbox{$#1\expandafter\OldSqrt\expandafter[\DHLindex]{#2\,}$}\lower0.4pt\box2}%
}
EDIT4: Unfortunately the root symbol has more whitespace above in bold math mode. Look at
\fboxsep0pt
\fbox{$f(x) = \OldSqrt{e^{2x}}$}
\fbox{\boldmath$ f(x) = \OldSqrt{e^{2x}}$}
Hence, this has to be considered when placing the "closing rule":
\makeatletter
\newcommand*\bold@name{bold}
\def\DHLhksqrt#1#2{%
\setbox0=\hbox{$#1\OldSqrt{#2\,}$}\dimen0=\ht0\relax%
\advance\dimen0-0.2\ht0\relax%
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0}%
{%
\hbox{$#1\expandafter\OldSqrt\expandafter[\DHLindex]{#2\,}$}%
\lower\ifx\math@version\bold@name0.6pt\else0.4pt\fi\box2%
}%
}
\makeatother
Such a big formula doesn't find its place in line; you could set (maybe locally) \lineskip
to 2pt instead of the default 1pt:
... end of the previous paragraph.
\begingroup
\setlength{\lineskip}{2pt}
The paragraph with the big $\dfrac{\Pr(X-a)}{\Pr(X-b)}$ which
spoils the appearance of the page.
\endgroup
(Note the blank line before \endgroup
to end the paragraph.)
However, the best way to typeset large formulas is to display them:
The paragraph with the big
\[
\frac{\Pr(X-a)}{\Pr(X-b)}
\]
which doesn't spoil the appearance of the page and
is clearer for the reader.
Best Answer
Unit for the macros is mu (mathunit 1mu=1/18em)
See also page 59 of mathmode document ->
texdoc mathmode