I've been trying to use tcolorbox to frame a reaction using the reaction environment from chemmacros. The use of \begin{tcolorbox}and \end{tcolorbox} does work:
\documentclass{exam}
\usepackage{chemmacros}
\usepackage{tcolorbox}
\chemsetup{modules = all}
\begin{document}
Document starts
\begin{tcolorbox}
\begin{reaction}
3 O2 -> 2 O3
\end{reaction}
\end{tcolorbox}
document continues here
\end{document}
This produces the document with no errors; however, as expected, the box spans the text width. I want the box to fit the reaction, so I tried to use the tcbox command. However, if I put it before the reaction environment, I get a bad math delimiter error and the reaction number appears inside the box, and if I use it inside it won't compile (it says LaTeX error: "kernel/empty-search-pattern" Empty search pattern. For immediate help type H . \end).
Any suggestions?


tcolorbox, since it occurs with\fboxand\mboxas well. – CampanIgnis Mar 28 '17 at 23:54