I know that we can redefine inequality-signs such as \le by simply doing \let\oldle\le and \def\le{\mathrel{...}}. But I have no idea how to redefine the equality-sign =. So if I want to automatically make some symbols blue, I can do so for inequality-signs but not for equality-signs. What can I do to achieve automatically blue equality-signs in math mode? That is, I want to still just type = in math mode and it will automatically be made blue. I do not mind complicated code as long as it only needs to be inserted once.


You need to make = math active.


% set up = to be math active
  \mathchardef\standardequal=\mathcode`= % save the standard =
  \mathcode`=="8000 % make = math active


a=b \\
a\standardequal b % for comparison


enter image description here

  • Thank you, but I am unable to understand the line \begingroup\lccode`~=`=\lowercase{\endgroup\def~}{...}. Could you please explain it?
    – user21820
    Oct 5 '20 at 8:50
  • @user21820 It's a very common trick for obtaining an active = (in this case) without doing explicit category code changes.
    – egreg
    Oct 5 '20 at 8:54
  • Can you give me a reference where I can learn this tricks and maybe other useful tricks as well? I have no idea what this one is doing.
    – user21820
    Oct 5 '20 at 9:03
  • I accepted your answer because it did what I asked for, but I still have absolutely no idea how it works, so it would be good if you can point me to some reference for at least this trick. For one, the \begingroup and \endgroup do not seem matched.
    – user21820
    Oct 8 '20 at 8:20
  • 1
    @user21820 The argument of \lowercase is processed, changing letters to their lowercase counterparts based on the current values of the \lccode array *without changing the category code, only the character code. Then the tokens are examined anew; however, the braces have already disappeared, so the \endgroup balances the \begingroup making just the assignment to \lccode to be undone. Thus at the end, TeX sees \def={...} (but the = has category code 13, active).
    – egreg
    Oct 8 '20 at 8:55

With LuaLaTeX, you can do that. See the following example. (Special thanks to @Mico's answer.)

%!TeX Program = lualatex
    function myreplace ( s )
    s = unicode.utf8.gsub ( s , '=', '\\textcolor{blue}{=}' )
    return s

myreplace, "myreplace")}
  • 1
    This is a really bad idea, because this would also match = in contexts like \looseness=1. Oct 14 '20 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.