2

Since can't set a label to a chemical reaction with chemfig package, the only solution is put the scheme between \begin{equation} and \end{equation}

\begin{equation}
\schemestart
2 \ce{H_{2}O} \arrow{<=>} \ce{H_{3}O^{+}} \+ \ce{OH^{-}}
\schemestop
\end{equation}

And this, works fine. So, I think to create a new newenvironment called "reaction": this is my attempt

\documentclass[12pt]{article}
\usepackage{chemfig}
\usepackage[version=3]{mhchem}

\newenvironment{reaction}
    {
    \centering
    \begin{equation}
    \schemestart
    \schemestop
    \end{equation}
    }

\begin{document}

    \begin{reaction}
    2 \ce{H_{2}O} \arrow{<=>} \ce{H_{3}O^{+}} \+ \ce{OH^{-}}
    \end{reaction}

\end{document}

This is the error message:

! Undefined control sequence. 2 \ce{H_{2}O} \arrow

Seems like \arrow sequence not works on reaction environment

How can I improve the new environment?

  • 2
    unrelated to your question but \centering has no effect on equations. Your \newenvironemntis missing the third argument with the end code, I assume you intended } after \schemestart and { before \schemestop so the environment body goes between those? – David Carlisle Jul 14 '20 at 11:19
  • Yes, I intend to put my \newenvironemnt content between \schemestart and \schemestop – user3204810 Jul 14 '20 at 11:30
5

You are missing a final argument to \newenvironment (picking up teh blank line so avoiding an error) so your equation is always empty and the environemnt content is following that.

enter image description here

The chemistry macros don't appear to like a normal newenvironment so using xparse here to grab the environment body

\documentclass[12pt]{article}
\usepackage{chemfig}
\usepackage[version=3]{mhchem}

\usepackage{xparse}
\NewDocumentEnvironment{reaction}{b}
    {%
    \begin{equation}%
    \schemestart
     #1
    \schemestop
    \end{equation}%
    }

\begin{document}

\begin{reaction}
    2 \ce{H_{2}O} \arrow{<=>} \ce{H_{3}O^{+}} \+ \ce{OH^{-}}
\end{reaction}

\end{document}
  • Thank you very much! – user3204810 Jul 14 '20 at 11:42

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.