1

I want to cross-refer a chemical reaction and to write chemical reactions I am using

\usepackage{chemformula}

to cite I am using

\usepackage{cleveref}

I want to cross-refer reactions using \cref{label}. How can I do it?

MWE

\documentclass[a4paper,oneside,12pt,openright]{book}
\usepackage{amsmath,amssymb} %for typing the mathematical equations and symbols
\usepackage[utf8]{inputenc} % input encoding
\usepackage{csquotes} %for using quotes command:\hyphenquote
\usepackage[T1]{fontenc} % font encoding
\usepackage{etoolbox,ragged2e,siunitx,mathtools}
\usepackage{indentfirst} % paragraphs
\usepackage[paper=a4paper,left=22mm, top=22mm, right=15mm, bottom=22mm]{geometry} %paper geometry  total={170mm, 257mm}
\usepackage{graphicx} %for figure
\usepackage{array} % for matrices
\usepackage{pgfplots} % for plots
\usepackage{caption} %names of figures and tables
\captionsetup[figure]{list=yes}
\captionsetup[table]{format=plain,labelformat=simple,labelsep=period}%
\usepackage[list=true,listformat=simple]{subcaption}
\pgfplotsset{width=10cm, compat=1.9}
\usepackage{color} %colors in document
\usepackage{xcolor} 
\usepackage[english]{babel}% base language and spacing
\frenchspacing
\renewcommand{\baselinestretch}{1.2}
\usepackage{mathrsfs}
\usepackage{chemformula}
\usepackage{cleveref}
\begin{document}
I want to cross refer following reaction

\ch{2H2+ O2 -> 2H2O}

As per above \cref{label} water is formed.

\end{document}

3 Answers 3

1

I defined a reaction environment, with its own counter:

\documentclass[a4paper,oneside,12pt,openright]{book}
\usepackage{amsmath,amssymb} %for typing the mathematical equations and symbols
\usepackage[utf8]{inputenc} % input encoding
\usepackage{csquotes} %for using quotes command:\hyphenquote
\usepackage[T1]{fontenc} % font encoding
\usepackage{etoolbox, ragged2e, siunitx, mathtools}
\usepackage{indentfirst} % paragraphs
\usepackage[paper=a4paper,left=22mm, top=22mm, right=15mm, bottom=22mm]{geometry} %paper geometry total={170mm, 257mm}
\usepackage{graphicx} %for figure
\usepackage{array} % for matrices
\usepackage{pgfplots} % for plots
\usepackage{caption} %names of figures and tables
\captionsetup[figure]{list=yes}
\captionsetup[table]{format=plain,labelformat=simple,labelsep=period}%
\usepackage[list=true,listformat=simple]{subcaption}
\pgfplotsset{width=10cm, compat=1.9}
\usepackage{xcolor}
\usepackage[english]{babel}% base language and spacing
\frenchspacing
\renewcommand{\baselinestretch}{1.2}
\usepackage{mathrsfs}
\usepackage{chemformula}
\usepackage{cleveref}
\newcounter{reaction}
\setcounter{reaction}{0}
\newenvironment{reaction}[1][]{\refstepcounter{reaction}\label{#1}\equation}{\tag{\arabic{reaction}}\endequation}
\crefname{reaction}{reaction}{reactions}
\Crefname{reaction}{Reaction}{Reactions}

\begin{document}

I want to cross refer following reaction
\begin{reaction}[label] \ch{2 H2 + O2 -> 2 H2O} \end{reaction}

As per above \cref{label}, water is formed.

\end{document}

enter image description here

3
  • 1
    It must be \ch{2 H2 + O2 -> 2 H2O} (more spaces) in order to give a meaningful chemical reaction (I know its wrong in the OP…)
    – cgnieder
    Commented Nov 4, 2019 at 20:58
  • 1
    \clemens: Yes, I didn't check that, but I indeed wondered what this prescript was ( I'm not a chemist…). Thanks!
    – Bernard
    Commented Nov 4, 2019 at 21:16
  • Thank you for your answer, it works like a charm. But when I refer to it using \cref it returns in Arabic numbering format even though I made changes in the code line as \roman. Could you please post the fix for that as well? Commented Nov 5, 2019 at 13:45
5

I'd use chemmacros with its reactions module. It uses chemformula per default and works with cleveref out of the box:

\documentclass{article}

\usepackage{chemmacros}
\chemsetup{
  modules = {reactions} ,
  formula = chemformula % not necessary: this is the default 
}
\usepackage{cleveref}

\begin{document}

\begin{reactions}
  2 H2 + O2 &-> 2 H2O "\label{rxn:water}" \\
  CH4 + 2 O2 &-> CO2 + 2 H2O "\label{rxn:methane}"
\end{reactions}

In \cref{rxn:water} water is formed. \Cref{rxn:methane} shows the combustion
of methane.

\end{document}

enter image description here

Customizations are easily possible, too:

\documentclass{article}

\usepackage{chemmacros}% uses chemformula as default
\chemsetup{
  modules = {reactions} ,
  reactions/tag-open  = ( ,
  reactions/tag-close = )
}
\renewcommand*\thereaction{\Roman{reaction}}

\usepackage{cleveref}

\begin{document}

\begin{reactions}
  2 H2 + O2 &-> 2 H2O "\label{rxn:water}" \\
  CH4 + 2 O2 &-> CO2 + 2 H2O "\label{rxn:methane}"
\end{reactions}

In \cref{rxn:water} water is formed. \Cref{rxn:methane} shows the combustion
of methane.

\end{document}

enter image description here

0

Is this what you are looking for? Also, you need some spaces in your equation (for example, H2+ should be converted to H2 +). I also stripped out many of the lines in your MWE to make it a little more minimal.

\documentclass[a4paper,oneside,12pt,openright]{book}

\usepackage{chemformula}
\usepackage{cleveref}
\begin{document}
    \begin{align}
    \ch{2 H2 + O2 &-> 2 H2O}  \label{water}  \\
    \ch{CH4 + 2 O2 &-> CO2 + 2 H2O} \label{methanecombustion}
    \end{align}


    As per above \cref{water} water is formed. And here is some \cref{methanecombustion} methane combustion.

\end{document}

enter image description here

You must log in to answer this question.

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