I would like to define new environments to highlight certain equations in some way. For example, I would like a highlighted equation to appear in red text or with a box around it. I have the red text version working but the boxed version is giving me a pair of related errors:
Missing } inserted. \begin{boxedeq*}
Extra }, or forgotten $. \end{boxedeq*}
Since there are unmatched braces in the before and after sections of the new environment, it is my understanding that I need to use \bgroup
and \egroup
instead of {
and }
. This works for the red text case but the errors indicate that it isn't working for the boxed case (a "missing" }
is inserted in the before section and an "extra" }
is found in the after section).
Here is the MWE:
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{color}
% equation/equation* environments highlighted in red
\newenvironment{higheq}{\textcolor{red}\bgroup\begin{equation}}{\end{equation}\egroup}
\newenvironment{higheq*}{\textcolor{red}\bgroup\begin{equation*}}{\end{equation*}\egroup}
% equation/equation* environments highlighted with box
\newenvironment{boxedeq}{\begin{equation}\boxed\bgroup}{\egroup\end{equation}}
\newenvironment{boxedeq*}{\begin{equation*}\boxed\bgroup}{\egroup\end{equation*}}
\begin{document}
\begin{higheq}
\sin^2(x) + \cos^2(x) = 1
\end{higheq}
\begin{equation}
\boxed{\sin^2(x) + \cos^2(x) = 1}
\end{equation}
\begin{boxedeq*}
\sin^2(x) + \cos^2(x) = 1
\end{boxedeq*}
\end{document}
And here is the output:
How do I avoid this error?
\boxed\bgroup...\egroup
is not at all equivalent to\boxed{...}
. In the former case the argument to\boxed
is\bgroup
. You should look at theempheq
package.\boxed{...}
?