This question already has an answer here:

In many of the inbuilt mathematica function, variables appear aqua like in:

enter image description here

However, when creating your own function, variables no longer have that green coloring and are instead colored like an undefined variable

enter image description here

Is there any way to define functions so that variables used in arguments like in the manner above can get the aqua syntax coloring?


marked as duplicate by Mike Honeychurch, acl, Mr.Wizard Jul 16 '14 at 1:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ you can set this via the preferences panel, the options inspector or a stylesheet. All of these methods have been discussed on this site. $\endgroup$ – Mike Honeychurch Jul 15 '14 at 23:53
  • $\begingroup$ @MikeHoneychurch That has to due with changing the syntax highlight coloring itself. I am asking how to get variables used in arguments of user-defined functions to exhibit that syntax coloring. $\endgroup$ – 1110101001 Jul 16 '14 at 0:08
  • $\begingroup$ ok. misunderstood. @acl has your answer $\endgroup$ – Mike Honeychurch Jul 16 '14 at 0:18
  • $\begingroup$ @MikeHoneychurch looks like a duplicate $\endgroup$ – acl Jul 16 '14 at 0:22

You can use SyntaxInformation. In this case,

SyntaxInformation[Lim] = {"ArgumentsPattern" -> {_, _, OptionsPattern[]}, 
   "LocalVariables" -> {"Limit", {2}}}

does what you want.

  • $\begingroup$ I also have another function ImplicitPlot[p_, q_, r_] := ContourPlot[p, q, r] and I tried doing something similar: SyntaxInformation[ImplicitPlot] := {"ArgumentsPattern" -> {_, _, _, OptionsPattern[]}, "LocalVariables" -> {"Plot", {2, 3}}} but it's not working for this one... any idea why? $\endgroup$ – 1110101001 Jul 16 '14 at 1:01
  • 1
    $\begingroup$ I'll take a look in a few hours if nobody else does so by then. Away from mathematica right now. $\endgroup$ – acl Jul 16 '14 at 1:02
  • $\begingroup$ Do SyntaxInformation[implicitPlot] ={"ArgumentsPattern" -> {_, _, _, OptionsPattern[]}, "LocalVariables" -> {"Plot", {2, 3}}} and does work. Make sure you use Set (=) and not SetDelayed := ! I searched for an explanation of the difference and found this which, to my surprise, I wrote myself. $\endgroup$ – acl Jul 16 '14 at 9:58

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