Since in my document I have to write a lot of math in colored box, I'd like to avoid to write $ inside every box. Is there a way to define newtcbox
in math mode?
I tried with \newtcbox{\mywbox}[1]{<options>}{$\displaystyle #1$}
but it doesn't work.
This is my latex code:
\usepackage{tcolorbox}
\newtcbox{\mywbox}{on line,colback=white,colframe=black,size=fbox,arc=3pt,boxrule=0.8pt}
\begin{document}
\obeylines
This \mywbox{$3x$} is in line math.
This $$y=\mywbox{$-5x$}-5+6$$ is not in line math.
\end{document}
I read about \tcboxmath
and \tcbhighmath
in the official tcolorbox manual, but I don't understand how to define them simply as the newtcbox and if they are what I need.
Best Answer
I would say
Your example can become
Change the names to your liking.
Avoid
$$
in LaTeX (and of course also\obeylines
).Should you need the boxes to behave in subscripts or superscripts, change the code into
Note that in this case you need that
\mywboxmath
is in math mode.