I'm not convinced that it's an improvement to force (most) \sqrt
expressions to have surds with the same height and depth. But, as always, if you really understand what you're doing, you'll probably be ok using the one-size-fits-almost-all approach.
The following, LuaLaTeX-based solution features (a) a utility LaTeX macro called \lsqrt
and (b) two Lua functions: lsqrt
does almost all of the real work, and checkroot
(which is called by lsqrt
) contains a list of conditions; if one (or more) of these conditions is met, \lsqrt
does nothing special, i.e., it behaves like the basic \sqrt
macro.
The default height of the horizontal bar of the square root symbol generated by \lsqrt
is set so that something such as k^2
will just fit. Note that this is a bit taller than what the OP required; however, as the difference in heights is just 0.6pt
(at least for Computer Modern with 10pt
as the main document font size), I think it's justifiable to go for this ever so slightly greater height. Of course, if you prefer a height that accomodates k
but not k^2
, just change both instances of \\vphantom{k^2}
to \\vphantom{k}
. (Aside: the \\
double-backslash symbol occurs because for Lua, \
has a special meaning too; however, the Lua-special and TeX-special meanings of \
are completely different. To output a single backslash character in Lua, it's necessary to input \\
.)

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{amsmath}
\usepackage{luacode} % for 'luacode*' env. and '\luastringN' macro
%% Lua-side code: 2 Lua functions: checkoptargroot, lsqrt
\begin{luacode*}
function checkroot ( s )
if s:find ( "\\[dt]?frac" ) -- \frac term
or s:find ( "\\int" ) -- integral symbol
or s:find ( "\\sum" ) -- summation symbol
or s:find ( "%^%s?%b{}" ) -- exponent term encased in matching curly braces
then
return true
else
return false
end
end
function lsqrt ( b , s ) -- this function does most of the work
if b=="" then -- no optional argument was provided to "\lsqrt"
if checkroot ( s ) then
tex.sprint ( "\\sqrt{".. s .."}" ) -- nothing special to do
else
tex.sprint ( "\\sqrt{\\smash{".. s ..
"}\\vphantom{k^2}}\\vphantom{"..s.."}" )
end
else -- need to handle non-empty optional argument
if checkroot ( s ) then
tex.sprint ( "\\sqrt["..b.."]{".. s .."}" ) -- nothing special to do
else
tex.sprint ( "\\sqrt["..b.."]{\\smash{".. s ..
"}\\vphantom{k^2}}\\vphantom{"..s.."}" )
end
end
end
\end{luacode*}
%% LaTeX-side code: utility macro to access the 'lsqrt' function
\newcommand\lsqrt[2][]{\directlua{lsqrt(\luastringN{#1},\luastringN{#2})}}
\begin{document}
$\sqrt{y}$ $\sqrt{x}$ $\sqrt{t}$ $\sqrt{k}$ $\sqrt{b_q^2}$ vs.\
$\lsqrt{y}$ $\lsqrt{x}$ $\lsqrt{t}$ $\lsqrt{k}$ $\lsqrt{b_q^2}$
\medskip
$\sqrt[3]{y}$ $\sqrt[4]{x}$ $\sqrt[5]{t}$ $\sqrt[6]{k}$ $\sqrt[7]{b_q^2}$ vs.\
$\lsqrt[3]{y}$ $\lsqrt[4]{x}$ $\lsqrt[5]{t}$ $\lsqrt[6]{k}$ $\lsqrt[7]{b_q^2}$
\medskip
$\sqrt{\frac{1}{2}}$ $\lsqrt{\frac{1}{2}}$,
$\sqrt[3]{\dfrac{1}{5}}$ $\lsqrt[3]{\dfrac{1}{5}}$,
$\sqrt{a_q^{-x^2/2}}$ $\lsqrt{a_q^{-x^2/2}}$
\end{document}
$\sqrt{x} \, \sqrt{y} \, \sqrt{X}$
). This leads to 3 different square root signs (ugly). A solution is desireable because the adjustments by hand are annoying.\smash[b]
or\phantom
by hand. With LuaTeX automatic solutions should be possible.