The \boldmath
macro does this. It is provided by the LaTeX core and switches to bold math for all following math material. There is an \unboldmath
to switch it off again. These macros must be used outside the math code.
\documentclass{article}
\begin{document}
\boldmath
$x=2$
\[ x=2 \]
\end{document}
If you can use LuaLaTeX instead of pdfLaTeX, it may be easier to just create a dedicated Lua function and set up an associated TeX "wrapper macro" rather than to try to hack the \num
macro of the siunitx
package. In the example below, the wrapper macro is called \mynum
, and its syntax is set up to be mimic the behavior of the \num
macro.
The only assumption that's made about about the numbers to be formatted is that their exponent part is non-empty, i.e., that the numbers contain an e<nn>
substring, where <nn>
is a positive or negative integer. With this setup, a number such as e1234
is a valid input for \mynum
(and for \num
too).
\documentclass{article}
\usepackage{siunitx}
\sisetup{exponent-product = \cdot,
round-mode = places}
%% Lua-side code
\usepackage{luacode}
\begin{luacode}
function formatnum ( prec, num )
if string.find ( num , "[%d%.]+[eE]" ) then
mant = string.format( "%."..prec.."f".."\\cdot", string.match ( num, "[%-%+]?[%d%.]+" ) )
else
mant = ""
end
expo = string.gsub ( num, ".-[eE]([%-%+]?)(%d+)", "10^{%1\\mathbf{%2}}" )
return ( tex.sprint( "$"..mant..expo.."$" ))
end
\end{luacode}
%% TeX-side code
\newcommand\mynum[2]{\directlua{ formatnum ( \luastring{#1}, \luastring{#2})}}
\begin{document}
\def\NumA{2.12e-14}
\def\NumB{12.34e56}
\def\NumC{e1234}
\num[round-precision=0]{\NumA}
\mynum{0}{\NumA}
\medskip
\num[round-precision=2]{\NumB}
\mynum{2}{\NumB}
\medskip
\num[round-precision=4]{\NumC}
\mynum{4}{\NumC}
\end{document}
Addendum: If you wanted to highlight the exponent in red instead of using bold-facing, you'd need to change \\mathbf{%2}
in the Lua code to \\color{red}%2
. Of course, either the xcolor
or color
package needs to be loaded in order to get access to the \color
macro.
\mynum{0}{2.12e-14}, \mynum{2}{-12.34e56}, \mynum{0}{e1234}
Best Answer
siunitx has never detected \mathbf. But you can change the font by setting the math-rm-key: