4

I'm trying to write chemical equations with mhchem, but I can't compile the code when I insert vertical bars (||) in the formula.

\usepackage[version=4]{mhchem}
.
.
\begin{center}
\ce{|M_{x}(H2O)_{\gamma}|[Al_{x}Si_{t-x}O_{2t}]-IZA}
\end{center}

When I write ||, the code don't compile, but if I replace it by [] it works fine.

Any suggestions?

3 Answers3

6

I don't know if the bars in my example are in proper places, but the idea is simple: putting them in math mode:

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

\begin{document}
\begin{center}
\ce{$|$M_{x}(H2O)_{\gamma}$|$ $|$Al_{x}Si_{t-x}O_{2t}$|$-IZA}
\end{center}

\end{document}

enter image description here

2

You could simply split up you formula.

\documentclass{article}

\usepackage[version=4]{mhchem}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{center}
|\ce{M_{x}(H2O)_{\gamma}}| \ce{[Al_{x}Si_{t-x}O_{2t}]-IZA}
\end{center}

\end{document}

enter image description here

Rico
  • 6,097
1

The other answers offered workarounds. As for the question, why this is not supported by the \ce macro, well, the author never considered this particular notation. If you can provide an argument that this is a standard chemical notation (preferably by a IUPAC colored book), he will be happy to include this into one of the next mhchem releases.

mhchem
  • 3,485
  • 12
  • 37
  • 2
    It seems that here is bug. For example \ce{M_{x}(H2O)_{\gamma}|} works, but \ce{|M_{x}(H2O)_{\gamma}} not and \ce{$|$M_{x}(H2O)_{\gamma}|} works again. Also works \ce{O2|M_{x}(H2O)_{\gamma}|}. Error is only if vertical bar is in beginning of chem formula. – Zarko Jan 03 '16 at 18:34