# Custom command with \ensuremath within \textbf

I have created a custom command to help me with scientific number notation:

\newcommand{\E}[1]{\ensuremath{\cdot 10^{#1}}}


The command works OK, but now I have a need to bold some of the numbers and the result is the following:

The code produced the image above is the following:

-4,25\E{-6}
\textbf{-1,73\E{-6}}


As you can see, the exponent part is not bolded.

My question is simple: how to bold the whole number?

-
Isn't the usage of siunitx easier here? – Christian Hupfer Mar 2 at 16:41
\newcommand{\E}[1]{\boldmath\ensuremath{\cdot 10^{#1}}\unboldmath}... but not recommended – Christian Hupfer Mar 2 at 16:42
@ChristianHupfer: I don't want to bold all the numbers, just the ones within \textbf. If there is not an easy way to do this, then I will look into siunitx. – alesc Mar 2 at 16:45
Actually, siunitx is the easiest way, in my point of view – Christian Hupfer Mar 2 at 17:01

I suggest to use the siunitx package and the detect-weight setting for is, with \num{...} as typesetter.

If the exponent-product key is omitted, the default x style for numbers is usesd.

The d-6 style will print as 10^{-6} then.

\documentclass{article}

\usepackage[detect-weight,mode=text,copy-decimal-marker=true,exponent-product=\cdot]{siunitx}

\begin{document}

\num{-1,73d-6}

\textbf{\num{-1,73d-6}}
\end{document}


-

I'd use a specific command:

\documentclass{article}

\newcommand{\anum}[2][n]{%
\mbox{%
\mathcode,=\numexpr\mathcode,-"6000
\if#1b\boldmath\fi
$#2$%
}%
}
\newcommand{\E}[1]{\cdot10^{#1}}

\begin{document}

\anum{-4,25\E{-6}}

\anum[b]{-1,73\E{-6}}

\end{document}


Note that the minus sign is a real minus and not a hyphen; also the comma leaves no unwanted space.

-