2

I just saw a post on a french Facebook LaTeX group saying this:

When using the french decimal separator (comma), the space between the number inside the radical is reduced.

The proposed MWE is (integer, english decimal, french decimal):

\documentclass{standalone}
\begin{document}
$\sqrt{1}, \sqrt{1.1}, \sqrt{1,1}$
\end{document}

which renders:

various radicals

The problem seems to come from the height of the comma itself and the radical to not stretch as much as visually expected.

Three actions were proposed in the discussion:

  1. use of \usepackage[locale=FR]{siunitx} and \num{1.1}
  2. use of {,} as separator
  3. use of \displaystyle

Actions 1 and 2 doesn't change anything to the radical height problem but they do have the advantage of reducing the extra space after the comma, which was not the purpose of the question at first, but still of interest.

Action 3 actually solves it. 1 and 2, again, correct the horizontal extra space after the comma.

Here is a comparison table: comparison table

And the code for it:

\documentclass{article}
\usepackage[locale=FR]{siunitx}
\usepackage{booktabs}
\begin{document}
    \begin{tabular}{@{}llllll@{}}
        \toprule
         & integer & English & French & \{,\} & siunitx \\ \midrule
        inline & $\sqrt{1}$ & $\sqrt{1.1}$ & $\sqrt{1,1}$ & $\sqrt{1{,}1}$ & $\sqrt{\num{1.1}}$ \\ \midrule
        displaystyle & $\displaystyle{\sqrt{1}}$ & $\displaystyle{\sqrt{1.1}}$ & $\displaystyle{\sqrt{1,1}}$ & $\displaystyle{\sqrt{1{,}1}}$ & $\displaystyle{\sqrt{\num{1.1}}}$ \\ \bottomrule
    \end{tabular}
\end{document}

Now I wonder: is there a way to have the proper radical height without using \displaystyle?

2

Square roots are a pain.

Here I smash every comma that happens to be inside a radical.

\documentclass{article}
\usepackage{amsmath,siunitx,letltxmacro,booktabs}

\sisetup{output-decimal-marker={,}}

\LetLtxMacro\ORIsqrt\sqrt

\DeclareRobustCommand{\sqrt}[2][]{%
  \begingroup
  \begingroup\lccode`~=`,\lowercase{\endgroup\let~}\smashedcomma
  \ifnum\mathcode`,="8000 \else\mathchardef\ORIcomma=\mathcode`, \fi
  \mathcode`,="8000
  \if\relax\detokenize{#1}\relax\ORIsqrt{#2}\else\ORIsqrt[#1]{#2}\fi
  \endgroup
}
\newcommand{\smashedcomma}{\smash{\ORIcomma}}

\begin{document}

\begin{tabular}{@{}llllll@{}}
\toprule
     & integer & English & French & \{,\} & siunitx \\ \midrule
inline & $\sqrt{1}$ & $\sqrt{1.1}$ & $\sqrt{1,1}$ & $\sqrt{1{,}1}$ & $\sqrt{\num{1.1}}$ \\
\midrule
displaystyle & $\displaystyle{\sqrt{1}}$ & $\displaystyle{\sqrt{1.1}}$ &
               $\displaystyle{\sqrt{1,1}}$ & $\displaystyle{\sqrt{1{,}1}}$ &
               $\displaystyle{\sqrt{\num{1.1}}}$ \\
\bottomrule
\end{tabular}

\[
\sqrt{\frac{\num{1,1}}{\num{1,1}}}+\sqrt{\frac{1}{1}}
\]

\end{document}

enter image description here

1
  • That is amazing, thank you @egreg. – Ivan May 23 '20 at 23:26

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.