# Error -\begin{…} on input line X ended by \end{document}- in new environment

I created a new environment to box equations with tcolorbox. In spite of it outputs well, it also brings me two lines of error

\begin{empheq} on input line 25 ended by \end{beqn}.

\begin{beqn} on input line 24 ended by \end{document}.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{empheq}
\usepackage{xcolor}
\usepackage{amsmath}

\definecolor{MainColor}{rgb}{0.0, 0.56, 0.0}

\newtcbox{\mymathbox}[1][]{%
nobeforeafter,math upper,tcbox raise base,enhanced,colframe=MainColor,

\newenvironment{beqn}[1]
{%
\begin{empheq}[box=\mymathbox]{equation*}
#1
}
{%
\end{empheq}
}

\begin{document}

\begin{beqn}
x_{1,2}=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
\end{beqn}

\end{document}


What I need to correct in my code?

The empheq environment looks for \endempheq at the end of the environment code, not \end{empheq}

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{empheq}
\usepackage{xcolor}
\usepackage{amsmath}

\definecolor{MainColor}{rgb}{0.0, 0.56, 0.0}

\newtcbox{\mymathbox}[1][]{%
nobeforeafter,math upper,tcbox raise base,enhanced,colframe=MainColor,

\newenvironment{beqn}[1]
{%
\empheq[box=\mymathbox]{equation*}
#1
}
{%
\endempheq
}

\begin{document}

\begin{beqn}
x_{1,2}=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
\end{beqn}

\end{document}


• Thank you for your answer. I am thinking that my question is too localized and will not contribute much to the community. Should I delete it? If yes, are you going to lose your earned points? – Cragfelt Sep 30 '17 at 20:36
• @Cragfelt: Of course I would loose the points ;-) And I think other have done (and will do) the same error, so you should keep the question anyway. – user31729 Sep 30 '17 at 22:15
• Oh ok. In that case, I will keep it. Thank you again for the advice. – Cragfelt Oct 1 '17 at 0:33