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!

2
  • It seems that chemmacros interprets the label like a subscript from a formula -> \chemformula_subscript:n
    – maphy-psd
    Apr 4, 2014 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, 2014 at 19:13

1 Answer 1

8

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}
4
  • The Problem regarding a number in the label still exists. Are there any plans to fix this too?
    – Niklas
    Aug 1, 2017 at 16:42
  • 2
    @Niklas put the whole label in between "..."
    – cgnieder
    Aug 2, 2017 at 6:20
  • I don't know back there, but the current documentation (2022) says that for cleveref we must use "\label{rxn:my-reaction}", rct is for fancyref and I think for hyperref? but surely rxn -> cleveref; rct -> fancyref May 11, 2022 at 4:35
  • @EduardoJiménez rct is used by fancyref through \def\fancyrefrctlabelprefix{rct}. Neither hyperref nor cleveref care about the prefix
    – cgnieder
    May 12, 2022 at 19:28

You must log in to answer this question.

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