[Tex/LaTex] Error -\begin{…} on input line X ended by \end{document}- in new environment

environmentstcolorbox

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,
    colback=white,arc=4pt,boxrule=2pt,drop fuzzy shadow}

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

Best Answer

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,
    colback=white,arc=4pt,boxrule=2pt,drop fuzzy shadow}

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

enter image description here

Related Question