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.
Asked
Active
Viewed 175 times
3
user21820
- 868
- 7
- 19
2 Answers
6
You need to make = math active.
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
% set up = to be math active
\begingroup\lccode~==\lowercase{\endgroup\def~}{\mathrel{\textcolor{blue}{\standardequal}}}
\AtBeginDocument{%
\mathchardef\standardequal=\mathcode= % save the standard = \mathcode=="8000 % make = math active
}
\begin{document}
\begin{gather}
a=b \
a\standardequal b % for comparison
\end{gather}
\end{document}
egreg
- 1,121,712
1
With LuaLaTeX, you can do that. See the following example. (Special thanks to @Mico's answer.)
%!TeX Program = lualatex
\documentclass{article}
\usepackage{xcolor}
\usepackage{luacode}
\begin{luacode}
function myreplace ( s )
s = unicode.utf8.gsub ( s , '=', '\\textcolor{blue}{=}' )
return s
end
\end{luacode}
\begin{document}
\directlua{luatexbase.add_to_callback("process_input_buffer",
myreplace, "myreplace")}
=
\end{document}
Niranjan
- 3,435
-
1This is a really bad idea, because this would also match
=in contexts like\looseness=1. – Henri Menke Oct 14 '20 at 12:14

\begingroup\lccode`~=`=\lowercase{\endgroup\def~}{...}. Could you please explain it? – user21820 Oct 05 '20 at 08:50=(in this case) without doing explicit category code changes. – egreg Oct 05 '20 at 08:54\begingroupand\endgroupdo not seem matched. – user21820 Oct 08 '20 at 08:20\lccodesomehow extends past the beginning of\lowercaseexpansion but not beyond that, but I think I am missing something. – user21820 Oct 08 '20 at 08:49\lowercaseis processed, changing letters to their lowercase counterparts based on the current values of the\lccodearray *without changing the category code, only the character code. Then the tokens are examined anew; however, the braces have already disappeared, so the\endgroupbalances the\begingroupmaking just the assignment to\lccodeto be undone. Thus at the end, TeX sees\def={...}(but the=has category code 13, active). – egreg Oct 08 '20 at 08:55~was defined to be=so... Ok thanks it makes sense now. – user21820 Oct 08 '20 at 09:19