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:

enter image description here

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:

enter image description here

  • $\begingroup$ 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 $\endgroup$
    – Sumit
    Commented May 28, 2016 at 12:32
  • $\begingroup$ @Sumit You're right; I'm not interested in that solution. I need something that works for a package function. $\endgroup$
    – QuantumDot
    Commented May 28, 2016 at 12:36
  • $\begingroup$ Could you explain further what is the goal? From your description I though that z should be colored, but it isn't. $\endgroup$
    – Kuba
    Commented Jun 6, 2016 at 8:35
  • $\begingroup$ @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? $\endgroup$
    – QuantumDot
    Commented Jun 6, 2016 at 10:58
  • 2
    $\begingroup$ Would SyntaxInformation[myfunc] = {"ArgumentsPattern" -> {_, {}, ___} help for your purpose? $\endgroup$
    – TimRias
    Commented Jan 9, 2018 at 8:57

1 Answer 1


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 =
     If[Length@OwnValues[#] > 0 || System`Private`HasOwnCodeQ[#],
      # ->

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

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

Then looking at the "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},
    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"]
  ] // Dataset


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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