5

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
  • 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
7

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}

enter image description here

Update 2016-11-26

Since v5.6 chemmacros has native support for cleveref. The code for the picture above:

\documentclass{article}

\usepackage{chemmacros}[2016/05/02]
\usechemmodule{reactions}

\usepackage{cleveref}

\begin{document}

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

See \cref{rct:ab}\ldots

\end{document}
| improve this answer | |
  • The Problem regarding a number in the label still exists. Are there any plans to fix this too? – Niklas Aug 1 '17 at 16:42
  • 1
    @Niklas put the whole label in between "..." – cgnieder Aug 2 '17 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.