13

Is there a LaTeX command for the equal (=) sign? I'd like to overwrite the command so that all equal signs in my document are colored green. But it seems I cannot do it with just the symbol =, which is not a command.

Mika H.
  • 3,451

1 Answers1

21

Ten years later, a better implementation.

\documentclass{article}
\usepackage{xcolor}

% preserve the original equals % and make = math active \AtBeginDocument{% \mathchardef\standardequals=\mathcode= \mathcode="8000 }

% define math active = to be green \standardequals \ExplSyntaxOn \cs_new_protected:Nn \mika_greenequals: { \mathcolor{green!70!red}{\standardequals} } \char_set_active_eq:NN = \mika_greenequals: \ExplSyntaxOff

\begin{document}

$a\standardequals b$

$a=b$

\end{document}

The top line is to show that spacing is right.

enter image description here

original answer

Every character can be turned into a command in math mode, but some special tricks are needed.

\documentclass{article}
\usepackage{xcolor}

\begingroup\lccode~== \lowercase{\endgroup\def~}{\mathrel{\textcolor{green}{\standardequals}}}

\edef\standardequals{\mathchar\the\mathcode`=\relax}

\AtBeginDocument{\mathcode`=\string"8000 }

\begin{document} $a=b$ \end{document}

enter image description here

egreg
  • 1,121,712