5

As title says I would like to use MathJax mhchem \pu{} command in my LaTeX document. FYI it is widely used in chemistry stackexchange for putting units.

But when used I get the error:

Undefined control sequence. ... \pu

Missing $ inserted. ... \pu{ ....

Extra }, or forgotten $. ... \pu{....}

I have included the usepackage command on my preamble:

\usepackage[version=3]{mhchem}

also tried different versions, all same error. I have also tried putting the \pu{...} with and without $$.

I would appreciate if you could help me know what is the problem and how I can solve it? maybe you can provide me a working example of \pu{} command?

3
  • 3
    We will likely need a clue as to what this does: it's not a command from the LaTeX mhchem package.
    – Joseph Wright
    Commented Dec 11, 2017 at 10:50
  • @JosephWright oh I thought it is a regular command of MathJax mhchem! it is widely used in chemistry stackexchange for putting units.
    – Foad
    Commented Dec 11, 2017 at 10:51
  • 3
    use the siunitx package for typesetting units instead
    – Troy
    Commented Dec 11, 2017 at 11:03

2 Answers 2

11

You cannot. The \pu (physical unit) command is a goodie specific to MathJax/mhchem. It is not part of LaTeX/mhchem.

For a LaTeX document, I recommend using the siunitx package. With that, you can achieve document-wide consistency of units.

The reasons to add \pu to MathJax/mhchem:

  • There was (is) no reasonable siunitx implementation for MathJax.
  • The concept of centrally defining a style, then using it for the rest of the document is not suited for sites like StackExchange.
  • MathJax/mhchem's \ce was frequently misused to typeset upright units.
  • Reusing the MathJax/mhchem parser and pre-renderer, an implementation of \pu was possible with just a few lines of code.

As you see, none of these reasons apply to LaTeX. Therefore, I never considered implementing \pu for LaTeX.

4

I found it used in https://chemistry.stackexchange.com/a/76935

From the above we can see that the first and second coefficients 
in the polynomial fit correspond directly to $A$ and $B$,
respectively. In this example, the energies are in wavenumbers
($\pu{cm^{-1}}$). Most quantum packages print in atomic units
(Hartrees) and dynamics packages print in kJ/mol, which is fine,
but be aware that in the above fit the units are incorporated into
$A$ and $B$.

A proper LaTeX setting would be with the siunitx package:

\documentclass{article}
\usepackage{siunitx}

\begin{document}

From the above we can see that the first and second
coefficients in the polynomial fit correspond directly
to $A$~and~$B$, respectively. In this example, the energies
are in wavenumbers~(\si{\per\centi\meter}). Most quantum
packages print in atomic units (Hartrees) and dynamics
packages print in~\si[per-mode=symbol]{\kilo\joule\per\mol},
which is fine, but be aware that in the above fit the units
are incorporated into $A$~and~$B$.

\bigskip

From the above we can see that the first and second
coefficients in the polynomial fit correspond directly
to $A$~and~$B$, respectively. In this example, the energies
are in wavenumbers~(\si{cm^{-1}}). Most quantum
packages print in atomic units (Hartrees) and dynamics
packages print in~\si{kJ/mol},
which is fine, but be aware that in the above fit the units
are incorporated into $A$~and~$B$.

\end{document}

You can directly use representations of the symbols, but it's much more flexible when names are used.

enter image description here

2
  • 2
    As the author of MathJax/mhchem, I'd recommend \pu{cm-1} and \pu{kJ/mol} for a chemisty.StackExchange posting.
    – mhchem
    Commented Dec 11, 2017 at 14:06
  • 2
    There are much nicer examples, like chemistry.stackexchange.com/q/86817/24052
    – mhchem
    Commented Dec 11, 2017 at 14:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .