# chemmacros reaction environment and cleveref reference

I have a problem with the automatic reference by cleveref and the chemmacros package. When i refer to a reaction with cleveref, then cleveref types "eq. (1)" because chemmacros use the equation environment. That's why a simple customization with \crefname, \creflabelformat or \crefformat has no effects. But i want, that cleveref detect the reaction and set the reference to reaction {1}. Here the MWE.

\documentclass{scrartcl}
\usepackage{chemmacros}
\usepackage{cleveref}
\begin{document}
Before a little text.
\begin{reaction}
A -> B \label{rxn:test}
\end{reaction}
After the ref with cleveref \cref{rxn:test}.
\end{document}


The cleveref package provides an advanced \label-command with a optional argument to overwrite the reference type.

\begin{reaction}
A -> B \label[reaction]{rxn:test}
\end{reaction}


Gives

A -> Breaction]rxn:test


But no erros and correct reference output. According to the cleveref documentation, you should use the folliwing code for the optional \label-command

\begin{reaction}
A -> B {\label[reaction]{rxn:test}}
\end{reaction}


Gives me 3 times the error

amsmath: Multiple \label's: label '[reaction]{rxn:test}' will be lost. \end{reaction}


But with a \crefname{reaction}{reaction}{reactions} and \creflabelformat{reaction}{#2{#1}#3} the reference output is correct.

During the investigations i found out, that with this code (add a 1 to the labeltag)

\begin{reaction}
A -> B {\label[reaction]{rxn:test1}}
\end{reaction}


several errors come and no correct ref output.

Undefined control sequence ...n:test\chemformula_subscript:n {1}}{{1}{1}}

Undefined control sequence ...ubscript:n {1}@cref}{{[reaction][3][]1}{1}}

amsmath: Multiple \label's: label '[reaction]{rxn:test\chemformula_subscript:n {1}}' will be lost. \end{reaction}

Undefined control sequence ...n:test\chemformula_subscript:n {1}}{{1}{1}}

Undefined control sequence ...ubscript:n {1}@cref}{{[reaction][4][]1}{1}}


chemmacros define the reaction by the environ. chemmacros or environ processes the optional \label-command incorrect.

Does anyone have an idea to connect chemmacros with cleveref? Thanks!

-
It seems that chemmacros interprets the label like a subscript from a formula -> \chemformula_subscript:n – maphy-psd Apr 4 '14 at 16:46
The reaction environment is a wrapper around an equation environment and I didn't build in the possibility of an optional argument to \label . But since I have scheduled the next update I see if I can add something – clemens Apr 4 '14 at 17:14
I know of the wrapper attribute. I studied the *.sty of chemmacros and cleveref 2 hours. So, therefore I thing is better to fix the reaction environment that the cleveref label command works, isn't it? – maphy-psd Apr 4 '14 at 19:13
That's the plan... – clemens Apr 4 '14 at 23:56

With version 4.5 (2014/04/08) chemmacros supports an optional argument to \label:

\documentclass{article}

\usepackage{chemmacros}[2014/04/08]

\usepackage{cleveref}
\crefname{reaction}{reaction}{reactions}
\creflabelformat{reaction}{#2\{#1\}#3}

\begin{document}

\begin{reaction}
A -> B \label[reaction]{rct:ab}
\end{reaction}

See \cref{rct:ab}\ldots

\end{document}


-