# Why does the former work but the latter doesn't?

The following MWE works well:

\documentclass{beamer}
\usepackage[most]{tcolorbox}

\begin{document}
\begin{tcolorbox}[title={This is a title},hbox]
This is a body.
\end{tcolorbox}
\end{document}


However, the following cannot be compiled with TeX Live 2018 XeLaTeX:

\documentclass{beamer}
\usepackage[most]{tcolorbox}
\newenvironment{TColorBox}[1]{\begin{tcolorbox}[title=#1,hbox]}
{\end{tcolorbox}}
\begin{document}
\begin{TColorBox}{This is a title}
This is a body.
\end{TColorBox}
\end{document}


Why does the former work but the latter doesn't?

What's the root cause?

• I've not tried, but my guess is the second becomes title=This is a title. Have you tried [title={#1},hbox] in your newenvironment? – Teepeemm May 25 '18 at 2:57
• I have tried, but no effect. – xmllmx May 25 '18 at 3:05

The error message that you are getting is

LaTeX Error: \begin{tcolorbox} on input line 6 ended by \end{TColorBox}.

This is a standard problem that you get when you try to define a new environment that contains another environment, essentially because LaTeX gets confused about which environment it needs to close next. One work around is to use:

\newenvironment{TColorBox}[1]{\tcolorbox[title=#1,hbox]}{\endtcolorbox}


which works because the TColorBox environment does not open another environment. However, I think that the "correct" way to do what you want is to use \newtcolorbox:

\documentclass{beamer}
\usepackage[most]{tcolorbox}

\newtcolorbox{TColorBox}[1]{title=#1,hbox}

\begin{document}

\begin{frame}{}
\begin{TColorBox}{This is a title}
This is a body.
\end{TColorBox}
\end{frame}

\end{document}


Here's the output: