# Conflict between mhchem and pdftooltip (pdfcomment package)?

I tried to hide some text into a pdftooltip, which was working fine up to now (when I used TeXLive 2011).

I now upgraded to MacTeX 2014 and now I get an error, if there is a chemical formula in this hidden Text.

Minimal example:

\documentclass[11pt]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage{hyperref}
\usepackage[pdftex]{graphicx}
\usepackage{color}

\usepackage[T1]{fontenc}
\usepackage[version=3]{mhchem}
\usepackage{pdfcomment}

\newcommand{\weg}[1]{\pdftooltip{\textcolor{red}{\tiny\bfseries{}w}}{#1}}

\begin{document}

\ce{CO2}

the following text is hidden: \weg{hidden text \ce{CO2}}

\end{document}

I'm using MacTeX 2014 and I get the following error:

./MinimalExample.tex:19: Undefined control sequence. \mhchem@ce ...ate
{s}\chardef \mhchem@ce@substate
=0\relax \mhchem@ce@result... l.19   ...text is hidden: \weg{hidden text
\ce{CO2}}

How can I solve that?

EDIT: with TeXLive 2011, there was no error message, but the chemical formula was not correctly written in the pdftooltip, e. g. \ce{ZrO2} became *"3222378 * . Now with Josef's solution, at least the characters of the formula seem to be printed correctly in the tooltip.

• This is Martin Hensel, the author of mhchem. Oh dear, that looks complicated. Unfortunately, I cannot offer a solution immediately. (I am about to rewrite some core parts completely, BTW.) I did not use pdfcomment before. It's kind of surprising that it worked before, because \pdfcomment cannot hande any math and \ce is using math mode internally. What was the output with your TeXLive 2011? – user65640 Nov 5 '14 at 6:50