6

Alright, I'm trying to make a command to insert a proton. This code works fine:

\documentclass[12pt,letterpaper]{article}
\usepackage{amssymb,mathtools}
\usepackage[version=3]{mhchem}

\newcommand{\tphoton}{$\gamma$}

\begin{document}
\tphoton
\end{document}

and this code works fine:

\documentclass[12pt,letterpaper]{article}
\usepackage{amssymb,mathtools}
\usepackage[version=3]{mhchem}

\begin{document}
\ce{$\gamma$}
\end{document}

Why doesn't this code work?

\documentclass[12pt,letterpaper]{article}
\usepackage{amssymb,mathtools}
\usepackage[version=3]{mhchem}

\newcommand{\tphoton}{$\gamma$}

\begin{document}
\ce{\tphoton}
\end{document}

It gives a "! Missing $ inserted.", 3 "! Extra }, or forgotten $."

  • \tphoton or \tproton, you decide. But example 1 throws an error right now, too. ;-) – lockstep Jan 15 '12 at 21:32
  • @lockstep Fixed: I pasted an old testcase in by accident.I switched to \tphoton since it was more minimal. – Canageek Jan 15 '12 at 21:34
7

The argument of mhchem's \ce already is a "hidden math mode". \ce{\bfseries B} will give

! LaTeX Error: Command \bfseries invalid in math mode.

Try \ensuremath instead:

\documentclass[12pt,letterpaper]{article}
\usepackage{amssymb,mathtools}
\usepackage[version=3]{mhchem}

\newcommand{\tphoton}{\ensuremath{\gamma}}

\begin{document}
\ce{\tphoton}
\end{document}
  • Why does \ce{$\gamma$} work then? (my guess is that it becomes ...$$\gamma$$..., which is also valid). – Bruno Le Floch Jan 15 '12 at 21:43
  • I guess that the \ce gobbles the $. \ce{$\gamma$}, \ce{$$\gamma$$} and even \ce{$$$\gamma$$$} work fine. – clemens Jan 15 '12 at 21:46

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.