Have bold unit with Siunitx

boldsiunitx

My question is relatively simple, but after reading the new siunitx documentation, I still don't have the answer.

How to make, in math mode, that the unit is sensitive to the commands \mathbf and \symbf and thus have units written in bold ?

For numbers, it works well, so I don't understand why it is not the case with units.

\documentclass{article}

\usepackage{fontspec, unicode-math, siunitx}

\sisetup{
mode=match,
reset-text-family = false ,
reset-text-series = false ,
reset-text-shape = false,
text-family-to-math = false ,
text-series-to-math = false,
propagate-math-font = true,
reset-math-version = false
}

\begin{document}

\noindent
xxxx $\mathbf{2 x = \qty{10}{\kilo\gram}}$ xxxx\\
xxxx $\symbf{2 x = \qty{10}{\kilo\gram}}$ xxxx.\\

\noindent
What I would like to have:\\
xxxx $\symbf{2 x = 10\, kg}$ xxxx.\\

\end{document}

enter image description here

Best Answer

I have logged the initial issue as https://github.com/josephwright/siunitx/issues/525. The reason this arises here is that the 'referenece' output here is 10\,\mathrm{kg}, and so we end up with \mathbf{10\,\mathrm{kg}} and get inconsistent bold.

The intention for propagate-math-font is that it covers font family, rather than other aspects: I should make this clearer. I will think about how best to address the issue, as there are arguments both ways here.

What I would say is that making math mode text bold is a job for \boldmath. I'd therefore expect to use

\documentclass{article}
\usepackage{siunitx}
\sisetup{reset-math-version = false}
\begin{document}
xxxx {\boldmath$2 x = \qty{10}{\kilo\gram}$} xxxx
\end{document}

here, perhaps with \mathbf around the x depending on the semantics. (\boldmath is essentially about appearance, \mathbf is suggesting that there is mathematical meaning to the choice of font.)


All that said, I've decided that I will extend the code here to cover \mathbf. Until that hits CTAN, you can use

\cs_gset_protected:Npn \__siunitx_print_math_auxiv:n #1
  {
    \bool_if:NTF \l__siunitx_print_math_font_bool
      {
        \__siunitx_print_math_aux:N
          \mathbf \mathit \mathsf \mathtt
          \q_recursion_tail \q_recursion_stop
      }
      { \__siunitx_print_math_auxv:n }
        {#1}
  }
Related Question