# Units in MathJax markup

https://worldbuilding.stackexchange.com/a/31762/885

So what's the right way to put units inside of TeX blocks? I remember a font directive but not what the word was. And it's a kludge anyway — was a proper unit macro notation ever added?

### Use \text{}.

This MathJaX code:

1 \times 10^{23} kg


produces this output:

$1 \times 10^{23} kg$

By wrapping the kg in \text{ }, we get:

1 \times 10^{23} \text{ kg}


which produces

$1 \times 10^{23} \text{ kg}$

• So what's the difference between mathrm and text? The latter might have a better chance of being remembered anyway. Commented Jan 4, 2016 at 5:50
• @JDługosz the only difference I've found is that mathrm strips spaces, text doesn't. Commented Jan 4, 2016 at 7:46
• So the tilde on the outside lets $\TeX$ decide the right amount of space, while a space inside of text forces it to be an actual space character in that font. Commented Jan 4, 2016 at 12:50
• You can also use something like 1 \times 10^{23} ~ \text{kg}: $1 \times 10^{23} ~ \text{kg}$
– user
Commented Jan 4, 2016 at 15:30