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
  • 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? Jul 14, 2020 at 11:19
  • Yes, I intend to put my \newenvironemnt content between \schemestart and \schemestop Jul 14, 2020 at 11:30

1 Answer 1

5

You are missing a final argument to \newenvironment (picking up the blank line so avoiding an error) so your equation is always empty and the environment 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}
1
  • Thank you very much! Jul 14, 2020 at 11:42

You must log in to answer this question.

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