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$
2

1 Answer 1

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$
1
  • $\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, 2015 at 5:41

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.