Check equality between colors

I worked it out.

\makeatletter
   \extractcolorspec{mycolor1}{\@spec@A}
   \extractcolorspec{mycolor2}{\@spec@B}
   \ifthenelse{\equal{\@spec@A}{\@spec@B}}{
      %TRUE
   }{
      %FALSE
   }
\makeatother

As Werner points out, etoolbox's e-TeX powerful funtionalities are preferable to what ifthen offers. The \ifdefequal is particularly handy here.

enter image description here

\documentclass{article}
\usepackage{etoolbox}
\usepackage{xcolor}

\makeatletter
\newcommand\ifcolorsequalthenelse[4]{%
    \extractcolorspec{#1}{\@spec@A}
    \extractcolorspec{#2}{\@spec@B}
    \ifdefequal{\@spec@A}{\@spec@B}%
    {%
        #3%
    }{%
        #4%
    }
}
\makeatother

\begin{document}

\colorlet{mycolor1}{red}
\definecolor{mycolor2}{rgb}{1 0 0.1}

\noindent
Test 1:\ifcolorsequalthenelse{mycolor1}{red}{equal}{not equal}\\
Test 2:\ifcolorsequalthenelse{mycolor1}{mycolor2}{equal}{not equal}

\end{document}

Tags:

Logic

Color