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.
1 Answer
$\begingroup$
$\endgroup$
1
You can use the built-in SyntaxInformation[]
as follows:
SyntaxInformation[f] = {"LocalVariables" -> {"Plot", {2, Infinity}}};
f[Sin[x] + 1, {x, 0, 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 YuCommented Dec 17, 2015 at 5:41
SyntaxInformation
docs (reference.wolfram.com/language/ref/SyntaxInformation.html) and also questions about its use here. The"LocalVariables"
property is what you need. $\endgroup$