# adding a lable to a newcommand in the preamble using mhchem and fancyref

I'm using [version=4]{mhchem} and fancyref as packages. In mchem's manual there is a code given for the preamble that allows easily to enumberate the chemical equations like the normal equations:

\makeatletter
\newcommand\reaction@[1]{$$\ce{#1}$$}
\newcommand\reaction@nonumber[1]%
{\begin{equation*}$$\ce{#1}$$\end{equation*}}
\newcommand\reaction{\@ifstar{\reaction@nonumber}{\reaction@}}
\makeatother


as I want to label these equations for refering to them, I changed the second line to \newcommand\reaction@[2]{$$\ce{#1}$$ \label{eq:#2}} which does in principal work. However when i refer to them with \fref{eq:label} they have the number of the chapter.section.subsection where the equation is placed and not the number given behind the equation. When I use instead the code $$\ce{Formula}\label{eq:Formula}$$ the referencing works fine and I get the number of the equation.

Does anyone can help me what is wrong with my modification of the preamble?

Here a minimal example:

\documentclass[12pt, a4paper, twoside, openright]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[english,ngerman]{babel}
\usepackage[version=4]{mhchem}
\usepackage{fancyref}

\makeatletter
\newcommand\reaction@[2]{$$\ce{#1}$$\label{eq:#2}}
\newcommand\reaction@nonumber[1]%
{\begin{equation*}$$\ce{#1}$$\end{equation*}}
\newcommand\reaction{\@ifstar{\reaction@nonumber}{\reaction@}}
\makeatother

\begin{document}
\chapter{Fuel Cell}
\section{General}
\subsection{Fundamentals}
The basic reaction of a hydrogen fuel cell  is very simple, as \fref{eq:FC} shows. To gain electric energy these reaction must be separated into the hydrogen oxidation reaction (HOR, \fref [plain]{eq:HOR}) which occurs at the >anode and the oxygen reduction reaction (ORR, \fref[plain]{eq:ORR}) at the >cathode. To maintain electroneutrality, the negative current flow has to be >compensated via ionic cunduction between the electrodes. For this an >electrolyte has to be chosen which is electronically insulating but >ionically conductive.
\reaction{H2 + 1/2O2 -> H2O}{FC}
\reaction{H2 -> 2H+ + 2e-}{HOR}
$$\ce{1/2O2 + 2e- -> O^2-}\label{eq:ORR}$$
\end{document}

• Welcome to TeX - LaTeX! Try \newcommand\reaction@[2]{$$\ce{#1}\label{eq:#2}$$}, i.e., place the label inside the equation – clemens Sep 4 '15 at 14:48
• Oh, that makes scence and solved the problem. Thank you very much :) – Thesiswriter Sep 4 '15 at 15:01

\newcommand\reaction@[2]{$$\ce{#1}\label{eq:#2}$$}

that is, place \label inside the equation in your definition, just like you do when you write
$$\ce{1/2O2 + 2e- -> O^2-}\label{eq:ORR}$$