Bug introduced in 9.0.1 or earlier and persists in 13.2.1
I'm setting up the SyntaxInformation
for a package I'm writing and I'm struggling to understand what the "ColorEqualSigns"
property is supposed to do, how one is meant to use it, and whether it works at all.
From what I can tell, it is meant to colour equal signs (i.e. =
) red, in positions where it is likely that the intended operator is Equal
, i.e. ==
, instead of Set
. This includes positions that normally take equations (like in Solve
) or logical tests (like in Which
). Is this a correct understanding of the expected behaviour?
However, I'm having trouble getting the Front End to reproduce this behaviour, both for my own functions and for the in-built ones.
For my own functions, code like
SyntaxInformation[f] = {"ColorEqualSigns" -> {1, 2}};
f[a = 1, b = 2, c = 3]
only marks the first one as an error:
To do the system-defined functions, one can get a comprehensive list by running
list = Select[
Table[
{symbol, SyntaxInformation[ToExpression[symbol]]}
, {symbol, Names["System`*"]}]
, (("ColorEqualSigns" /. #[[2]]) =!= "ColorEqualSigns") &]
the output of which is nicely formatted by TableForm[{#1, {"ColorEqualSigns"} /. #2} & @@@ list]
.
And All
DSolve 1 1
For 2 2
If 1 1
Implies All
Nand All
NDSolve 1 1
NDSolveValue 1 1
Nor All
Not All
NRoots 1 1
NSolve 1 1
Or All
Reduce 1 1
Solve 1 1
SolveAlways 1 1
Which Odd
While 1 1
Xor All
From these, only If
and While
seem to work as intended. As a test, see the syntax colouring on the following:
And[a = 1, b = 2]
DSolve[y'[x] = y[x], y, x]
For[i = 0, i = 5, i++, Print[i]]
If[i = j, a, b]
Implies[a = b, c = d]
Nand[a = 1, b = 2]
NDSolve[y'[x] = y[x], y, x]
DSolveValue[{y'[x] = y[x] Cos[x + y[x]], y[0] = 1}, y, {x, 0, 30}]
Nor[a = 1, b = 2]
Not[a = 1]
NRoots[1 + 2 x + 3 x^2 + 4 x^3 = 0, x]
NSolve[x^5 - 2 x + 3 = 0, x]
Or[a = 1, b = 2]
Reduce[x^2 - y^3 = 1, {x, y}]
Solve[x^2 + a x + 1 = 0, x]
Solve[x^2 + a x + 1 = 0, x]
Which[a = 1, b = 2, c = 3, d = 4, e = 5, f = 6]
While[n = 4, n++]
Xor[a = 1, b = 2]
which render on my machine (MM 11.0.0, 10.3.0, 10.1.0 and 9.0.1 over Ubuntu) as
Note that e.g. the second equals sign in And[a = 1, b = 2]
is not marked as erroneous, which is inconsistent with the rule "ColorEqualSigns" -> All
in SyntaxInformation[All]
. This is present at least since early 2013, as pointed out in this post.
Is this the intended behaviour?