5

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}
9

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.

\ce{NH3(g) + HCl(g) -> $\textbf{\ce{NH4Cl}}$(s)}

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).

  • 1
    Approved! I should have used the same solution as you. – Sebastiano Jul 14 at 9:23
3

Try

  • using \ce in math mode (this dose change the output when you use a text font that looks different from the math font, or in headings, as commented by @mhchem) and
  • using \mathbf instead of \textbf

See this example:

\documentclass{article}
\usepackage[version=4]{mhchem}

\begin{document}
$\ce{NH3(g) + HCl(g) -> \mathbf{NH_4Cl}(s)}$
\ce{NH3(g) + HCl(g) -> NH_4Cl(s)}
\end{document}

enter image description here

  • 2
    Using \ce in math mode does change the output when you use a text font that looks different from the math font, or in headings. – mhchem Jul 14 at 6:21
  • @mhchem thanks. I have updated the answer. – Johannes Z Jul 14 at 18:00
1

It works flawlessly with chemformula, with the difference that the indeterminate coefficients should be typeset in math.

\documentclass{article}

\usepackage{chemformula}

\begin{document}

\ch{$a$ A + $b$ B -> $c$ C + $d$ D}

\ch{$a$ A + $b$ B -> $c$ \textbf{C} + $d$ D}

\ch{NH3(g) + HCl(g) -> \textbf{NH4Cl}(s)}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.