1

Consider the following MWE:

\documentclass{article}
\usepackage{mhchem}

\begin{document}

\ce{{}^3He} has a higher vapour pressure, and therefore a lower boiling point, 
than \ce{{}^4He}: the result of this is that pumping away the most energetic 
molecules from the bottom layer preferentially removes \ce{{}^3He}.

\end{document}

which yields the (correct) output. (I don't have enough rep to post three images separately!)

Attempting to package the awkward \ce command into a custom macro messes up the spacing with the following words, though not with punctuation:

\documentclass{article}
\usepackage{mhchem}

\newcommand{\HeThree}{\ce{{}^3He}}
\newcommand{\HeFour}{\ce{{}^4He}}

\begin{document}

\HeThree has a higher vapour pressure, and therefore a lower boiling point, than \HeFour: the result of this is that pumping away the most energetic molecules from the bottom layer preferentially removes \HeThree.

\end{document}

Placing a fixed space (~) in the macro naturally reverses this, so the punctuation spacing is now incorrect:

\newcommand{\HeThree}{\ce{{}^3He}~}
\newcommand{\HeFour}{\ce{{}^4He}~}

The outputs of these three arrangements are as follows:

enter image description here

What is the best way to get a consistent, correct spacing with a macro, that doesn't rely on me manually having to place a ~ after each time the macro precedes a word?

(I have the latest versions of TeXLive and mhchem installed)

  • 2
    This isn't a bug, but just the nature of the way TeX digests macro names (it thus has nothing to do with mhchem). The proper usage (in your 2nd code segment) is, thus, \HeThree{} has a higher.... Otherwise, the trailing space is considered a terminating token for \HeThree rather than a space in its own right. – Steven B. Segletes Jul 21 '17 at 12:32
  • 2
    \def\definece#1#2{\expandafter\def\csname ce:#1\endcsname{\ce{#2}}} and \def\cn#1{\csnanme ce:#1\endcsname} would let you define (\definece{he3}{{}^3He})keywords and use \cn{he3} or whatever name you choose. I think it will be clear and you won't need to take care of the space after the macro. – Manuel Jul 21 '17 at 12:34
  • Both of the comments make sense, thank you! I am a bit disappointed that then there is no way of making a "clean" macro in this case... – tusky_mcmammoth Jul 21 '17 at 12:52
  • What do you mean with clean? Manuel's suggestion is very clean. – TeXnician Jul 21 '17 at 12:56
  • @TeXnician that is true (I am currently using it, although I had to correct \csnanme); I meant in the sense that one could just type \hethree without any braces. But I guess even LaTeX convenience has its limits ;) – tusky_mcmammoth Jul 21 '17 at 13:08
  • 1
    As mentioned above, LaTeX eating up spaces after macros is a common pitfall and is handled early on in every LaTeX introduction. // Use \ce{^3He} instead of \ce{{}^3He}. // Find alternatives for things you find awkward. – mhchem Jul 21 '17 at 18:07
  • You can use your definition and the xspace package: \newcommand{\HeThree}{\ce{^3He}\xspace}. This addresses the issue. – TeXnician Jul 21 '17 at 18:50
  • Argh, how embarrassing! I've never used custom macros for text shorthand, so I've never had this issue and thought it was specific to mhchem... thank you for the responses anyway, I have now done my reading! – tusky_mcmammoth Jul 21 '17 at 22:31

0 Answers0