<div dir="ltr"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div class="h5">
<br>
</div></div>Here is a hackish solution:<br>
<br>
\documentclass{minimal}<br>
\usepackage{xparse}<br>
\DeclareSymbolFont{monospace}{OT1}{cmtt}{m}{n}<br>
\ExplSyntaxOn<br>
\cs_new_eq:NN \orig_mathbf:n \mathbf<br>
\RenewDocumentCommand \mathbf { m } {<br>
\orig_mathbf:n {<br>
\prg_stepwise_inline:nnnn { `0 } { \c_one } { `9 } {<br>
\mathcode ##1 = \numexpr "100 * \symmonospace + ##1 \relax<br>
}<br>
#1<br>
}<br>
}<br>
\ExplSyntaxOff<br>
\begin{document}<br>
$abc 012 \mathbf{abc 012} abc 012$<br>
\end{document}<br>
<br>
<br>
</blockquote></div><br>I am not much familar with xparse. Can you tell me why this does not work:<br><br>
<style type="text/css">p, li { white-space: pre-wrap; }</style>
<p style="margin: 0px; text-indent: 0px;">\documentclass{minimal}</p>
<p style="margin: 0px; text-indent: 0px;">\usepackage{xparse}</p>
<p style="margin: 0px; text-indent: 0px;">\DeclareSymbolFont{monospace}{OT1}{cmtt}{m}{n}</p>
<p style="margin: 0px; text-indent: 0px;">\newcommand{\test}[1]{%</p>
<p style="margin: 0px; text-indent: 0px;">\textbf{#1}</p>
<p style="margin: 0px; text-indent: 0px;">\ExplSyntaxOn</p>
<p style="margin: 0px; text-indent: 0px;">\cs_new_eq:NN \orig_mathbf:n \mathbf</p>
<p style="margin: 0px; text-indent: 0px;">\RenewDocumentCommand \mathbf { m } {</p>
<p style="margin: 0px; text-indent: 0px;"> \orig_mathbf:n {</p>
<p style="margin: 0px; text-indent: 0px;"> \prg_stepwise_inline:nnnn { `0 } { \c_one } { `9 } {</p>
<p style="margin: 0px; text-indent: 0px;"> \mathcode ##1 = \numexpr "100 * \symmonospace + ##1 \relax</p>
<p style="margin: 0px; text-indent: 0px;"> }</p>
<p style="margin: 0px; text-indent: 0px;"> #1</p>
<p style="margin: 0px; text-indent: 0px;"> }</p>
<p style="margin: 0px; text-indent: 0px;">}</p>
<p style="margin: 0px; text-indent: 0px;">\ExplSyntaxOff</p>
<p style="margin: 0px; text-indent: 0px;">}</p>
<p style="margin: 0px; text-indent: 0px;">\begin{document}</p>
<p style="margin: 0px; text-indent: 0px;">\test{test}</p>
<p style="margin: 0px; text-indent: 0px;">$abc 012 \mathbf{abc 012} abc 012$</p>
<p style="margin: 0px; text-indent: 0px;">\end{document}</p><br></div>