6
$\begingroup$

Many built-in functions can recognize variables. For example, function 'Table' makes its iterator change color. How can I implement a function that has a similar behavior? In this function, I can pass a symbolic expression to it and specify some target variables.

$\endgroup$
6
$\begingroup$

You can use the built-in SyntaxInformation[] as follows:

SyntaxInformation[f] = {"LocalVariables" -> {"Plot", {2, Infinity}}};

f[Sin[x] + 1, {x, 0, 1}]

enter image description here

$\endgroup$
  • $\begingroup$ Is there a way to colorize variables using different template? I tried "LocalVariables" -> {{"Table", {2, 2}}, {"Solve", {3, 3}}} but it didn't work. $\endgroup$ – Louis Yu Dec 17 '15 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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