# Is there a syntax coloring type that highlights only when not in a list?

How do I define the syntax coloring of local variable of function myfunc so that it only colors the variable that is not in a List?

For example,

SyntaxInformation[myfunc] = {"LocalVariables" -> {"Integrate", {2,2}}}


leads to the following syntax coloring:

I only want coloring like in the first line. I don't want the coloring appearing in the second line. In the second case, it should not be colored, and should just look like:

• This is probably not what you are looking for, but you might find it interesting How to change the font color of a variable in whole input cell – Sumit May 28 '16 at 12:32
• @Sumit You're right; I'm not interested in that solution. I need something that works for a package function. – QuantumDot May 28 '16 at 12:36
• Could you explain further what is the goal? From your description I though that z should be colored, but it isn't. – Kuba Jun 6 '16 at 8:35
• @Kuba In the function myfunc, only the second argument is a local variable. myfunc only takes a symbol in the second argument. It does not take a List in the second argument. Therefore, the second argument should be colored as a local variable only if it is a symbol, and not if it is a list. In the example above, the local variable is x and should be colored if it appears in the second argument. But if a List appears in the second argument, the x inside the List should not be colored. How do I prevent x from being colored if it is in a list? – QuantumDot Jun 6 '16 at 10:58
• Would SyntaxInformation[myfunc] = {"ArgumentsPattern" -> {_, {}, ___} help for your purpose? – mmeent Jan 9 '18 at 8:57

Here is my argument for why I think this is not possible:

First, we'll gather all the SyntaxInformation out there and GroupBy key:

sinfoAll =
Association@
ToExpression[
Join[
Names["**"],
Names["***"]
],
StandardForm,
Function[Null,
If[Length@OwnValues[#] > 0 || SystemPrivateHasOwnCodeQ[#],
Nothing,
# ->
SyntaxInformation[#]
],
HoldAllComplete
]
];

sinfoGood =
DeleteCases[sinfoAll, {} | \$Failed];

sinfoVals =
GroupBy[DeleteDuplicates@Flatten@Values@sinfoGood, First -> Last];


Then looking at the "LocalVariables":

sinfoVals["LocalVariables"]

{None, {"Manipulate", {2, \[Infinity]},
"Lexical"}, {"Solve", {2}}, {"Plot", {2, 3}}, {"Plot", {2,
4}}, {"D", {2, \[Infinity]}}, {"Table", {2, \[Infinity]}}, \
{"Solve", {2, \[Infinity]}}, {"Integrate", {2, \[Infinity]}}, \
{"Limit", {2}}, {"Plot", {3, \[Infinity]}}, {"Plot", {2}}, \
{"Manipulate", {2}}, {"Plot", {2, \[Infinity]}}}


We can try each of these in turn:

Block[{m = 1},
AssociationMap[
Function[
With[{s = ToExpression["f" <> ToString[m++]]},
SyntaxInformation[s] = {"LocalVariables" -> #};
{
Style[s[x*y*z, x, y, z], "Input"],
Style[s[x*y*z, { x, y, z}], "Input"]
}
]
],
sinfoVals["LocalVariables"]
]
] // Dataset
`

And we find that the opposite of what you want seems to be possible, but what you want does not.