I'm trying to typeset a chemical equation using the mhchem
package, and I want to bold just one part of the equation (to emphasize the product, in this case).
If I type \ce{a A + b B -> c \textbf{C} + d D}
, then that produces a A + b B → c C + d D. That's perfectly fine, of course. But I cannot put any more complex chemical formulas within the \textbf{}
command. If I enter, for example, \ce{NH3(g) + HCl(g) -> \textbf{NH4Cl}(s)}
, ammonium chloride is typeset as NH4Cl(s), without the subscript.
I tried writing the subscript manually (NH_4Cl
), but $\ce{NH3(g) + HCl(g) -> \textbf{NH_4Cl}(s)}$
did not work, and instead gave me a bunch of errors (missing $
, extra } or forgotten $
, missing {
, and missing }
).
I'm pretty new here so I'm not exactly sure how this MWE thing works — I don't have much that works, but as far as I can tell the code I was using to try things out seems to be pretty close to a MWE. Please let me know if I should provide anything else.
\documentclass{article}
\usepackage[version=4]{mhchem}
\begin{document}
\ce{a A + b B -> c C + d D}
\ce{a A + b B -> c \textbf{C} + d D}
\ce{NH3(g) + HCl(g) -> \textbf{NH4Cl}(s)}
\end{document}
Best Answer
An
\textbf
is a hard break inside a\ce
. What goes inside\textbf
's argument is not processed by the mhchem package.This is the way to go.
Use
$
to indicate that you want to escape mhchem parsing (mhchem does the correct guessing that\textbf
and the next{}
belong together, but using$
is much clearer). Then use\textbf
, then use\ce
inside.The
$
part (or the\textbf
for that matter) might interrupt the mhchem flow. The succeeding(s)
works fine, here, but you might not be always so lucky (for instance, a$\textbf{4}$
would not be recognized as a number).