# \mathsf{} prints digits in serif font

I am using mathsf{} in a command to mark special kinds of variables in a formula.

I have:

\newcommand{\mycmd}[1]{\mathsf{#1}}


In formulas I usually have

$\mycmd{specialvariable_1} = yada yada yada$


Now I noticed that the digits in the subscript are still printed in the serif font. This also happens for non-subscript numbers. A minimal example is:

$\mathsf{a5\,b_3}$


here the digits are printed in a serif font, the letters are printed in a sans-serif font.

How to force LaTeX to also print the digits in a sans-serif font?

(Maybe of interest: my command is often nested in other commands that occasionally are themselves nested in other commands...)

[Update] As requested I made a minimal working example. It seems the package sansmath is the problem. Without the package, the digits are printed in sans-serif, with the package, the digits are printed with serifs. Nevertheless this seems a bit counterintuitve...

\documentclass[11pt]{scrbook}

\usepackage{sansmath}

\begin{document}
$\mathsf{a5\,b_3}$
\end{document}

• Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Apr 22 '14 at 9:33
• Please provide an MWE. This depends on your font set-up and tex engine. If you use \showoutput the log file will tell exactly which fonts are being used. In a standard article document, the digits inside \mathsf are taken from cmss, the sans serif font, even when they are subscripts. – Andrew Swann Apr 22 '14 at 10:01
• Unfortunately sansmath does not redefine the \mathsf command. You just have to put \sansmath in the preamble and then all the maths in your document will use the sans fonts. – Thruston Apr 22 '14 at 11:16
• If you just want occasional maths symbols in sans, then you don't need sansmath. – Thruston Apr 22 '14 at 11:17
• @Thruston, I removed the sansmath package and now it works as expected. If you post your comment as answer I will accept it as correct. – cpt. jazz Apr 22 '14 at 13:42

The sansmath package redefines how numbers are handled, making them \mathord instead of \mathalpha. It does this because it takes the letters from the slanted sans serif font for math characters under \sansmath, and usually you do not want the numbers to be the slanted version, but it is incorrectly affecting the normal math version. Either drop the sansmath package or define your command as follows:

\newcommand{\mycmd}[1]{\mbox{\sansmath$\mathsf{#1}$}}


taking advantage of \mathsf working correctly in the sans math version.

\documentclass[11pt]{scrbook}

\usepackage{sansmath}

\newcommand{\mycmd}[1]{\mbox{\sansmath$\mathsf{#1}$}}

\begin{document}

$x = \mycmd{a5b_3},\quad y \ne \mathsf{a5b_3}$
\end{document}