8

When I load the unicode-math package, the placement of $\surd$ is below the text baseline, like this:

enter image description here

(I've included the $\exists$ to show it's not affecting every math mode symbol.) I would, of course, like it to look like this, which is what I see without loading unicode-math:

enter image description here

How can I fix this?

MWE:

\documentclass{article}
\usepackage{unicode-math}
\begin{document}
    $\surd$blah
\end{document}
Jigsaw
  • 935
  • This problem isn't present when OpTeX is used: \fontfam[lm] $\surd$blah \bye. I don't know why only LuaLaTeX and XeLaTeX have this problem. – wipet Aug 28 '23 at 04:20
  • Somehat related: https://tex.stackexchange.com/questions/168806/break-in-square-root-line – John Kormylo Aug 28 '23 at 13:51

3 Answers3

6

The issue is with the math font. Latin Modern Math places this symbol in a rather unconventional way (it's related to how legacy TeX fonts had to place extensible characters, but there's no real reason why this is done in an OpenType font).

You can either select a different font, patch Latin Modern Math or use \sqrt to get a \surd like symbol:

\documentclass{article}
\usepackage{unicode-math}
\AtBeginDocument {%
  \renewcommand \surd {\sqrt{\vphantom{a}}}%
}
\begin{document}
$\surd$blah
\end{document}

enter image description here

5

In the legacy TeX symbol fonts, the square root symbol hangs from the baseline and its (very small) height is used as the thickness of the vinculum. Due to how math lists are transformed into horizontal lists, the symbol is then raised suitably.

The developers of Latin Modern Math simply took the symbol from Computer Modern with the same feature.

In all other OpenType math font I know, the “surd” symbol sits on the baseline.

If you plan to experiment with different math fonts, you can write code that chooses whether to keep the surd as defined or to raise it.

\documentclass{article}
\usepackage{unicode-math}

%\setmathfont{Libertinus Math}

\makeatletter \AtBeginDocument{% \sbox\z@{$\surd$}% \ifdim\ht\z@<1ex \RenewDocumentCommand{\surd}{}{\mathpalette\surd@\relax}% \fi } \newcommand{\surd@}[2]{% \raisebox{\depth}{$\m@th#1\Umathchar"0 "2 "221A$}% } \makeatother

\begin{document}

$\surd$blah

$\scriptstyle\surd b$

\end{document}

With Libertinus Math commented, you get

enter image description here

With Libertinus Math, you get

enter image description here

egreg
  • 1,121,712
3

You can define \surd like \mathop and if you put it to {..} then it behaves like \mathord (usable for horizontal spacing).

\def\surd{{\mathop√}}
%% test:
$\surd b$lah
wipet
  • 74,238