I was looking for a simpler way to add color to math mode. Specifically, I wanted different parts of an equation to have different colors in order to better correlate with colors in a figure. The only thing I could find that worked was using \begingroup and \group. While the code below worked, I was wondering if someone had a simpler way of doing it. I couldn't find anything else looking around...
\usepackage[usenames, dvipsnames]{color}
\definecolor{myred1}{RGB}{255, 0, 0}
\definecolor{myyellow1}{RGB}{255, 255, 219}
\definecolor{mygreen1}{RGB}{0, 255, 0}
\definecolor{mygreen2}{RGB}{0, 126, 0}
\definecolor{myblue1}{RGB}{0, 0, 255}
\begin{equation}
\frac{
\begingroup
\textcolor{myblue1}
{a}
\endgroup
}
{
\begingroup
\textcolor{myred1}
{b}
\endgroup
}
=
\frac{
\begingroup
\textcolor{mygreen2}
{a + b}
\endgroup
}
{
\begingroup
\textcolor{myblue1}
{a}
\endgroup
}
\end{equation}
\color{myred1}{b}
, for instance. Or even shorter, make a new command with\newcommand\myred[1]{{\color{myred1}{#1}}}
and then use\myred{b}
in the equation. Unfortunately you can't have commands with numbers, but I think you'll make do!\begingroup
and\endgroup