# newenvironment and chemfig

Since can't set a label to a chemical reaction with chemfig package, the only solution is put the scheme between and

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


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
$$\schemestart \schemestop$$
}

\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?

• 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

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.

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}
{%
$$% \schemestart #1 \schemestop$$%
}

\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