# Document font instead of math font in chemical formula (mhchem package)

I would like to write all chemical formulas in my document using the mhchem package which facilitates the use of the document font. It works quite nicely so far, but it fails for the letter "x".

This is how it should look like:

This is the result using \ce{NO_x}:

Do you have any suggestions on how to use the document font (and not the math font) for the letter x in chemical formulas?

Interestingly, though, it does work for uppercase letters:

• Note that the x shall be italic, see: chemistry.stackexchange.com/questions/20315/… – yo' May 11 '16 at 10:34
• @yo' is right. The IUPAC recommendations are very clear. It also fits the general rule: variables are typeset in italics. But if you insist: \ce{NO_{\text{x}}} – clemens May 11 '16 at 11:28
• Or use chemformula instead of mhchem and use \ch{NO_x} (the correct input then would be \ch{NO_{$x$}} which means it requires a little more thinking and typing of the user). – clemens May 11 '16 at 11:30

\ce{NO_{\text{x}}} does the trick!

MWE

\documentclass{article}
\usepackage{mhchem}

\begin{document}
\ce{NO_{\text{x}}}
\end{document}

• Thank you - even though it is not necessary any more for my case, it could be useful for other users. – HyperCube May 11 '16 at 11:55
• @Sr. Schneider: I get the x in roman. – Bernard May 11 '16 at 12:45
• @Bernard when you use \ce{NO_x}? – clemens May 11 '16 at 16:42
• @clemens: No – using \ce{NO_\text{x} or \ce_\mathrm{x} . – Bernard May 11 '16 at 16:54
• @Bernard that's the expected output. (I get errors with \ce{NO_\text{x}} but \ce{NO_{\text{x}}} compiles fine) – clemens May 11 '16 at 17:34
1. For correct typesetting, it should be italic. See the other answers and comments with links. Leave as is and you are correct.

\ce{NO_x} will render NO in upright text font and x in italic text font. Try another text font (for instance \sffont) and you'll see. Put the command into a headline and everything will look as it should be.
On the other hand, if you use mhchem in math mode like $\ce{NO_x}$, this will render NO in upright math font and x in italic math font.
1. If you really need a supscript with an upright x, you could write \ce{A_{\text{x}}} as others suggested. However, this will force text font and therefore is not recommended in math mode (unless the fonts really match well). The preferred way is to write \ce{A_{{x}}} as this will result in correct fonts, regardless whether used inside or outside of math mode.
• I searched the manual for an official way but I didn't get that {…} gives upright text (depending on the surrounding font settings) the first time :/ Thinking about it now it's rather obvious, though. – clemens May 11 '16 at 17:40