I would like to know if there is a possibility to automatically color the variables with the same name with the same color. For example, like in the picture below:

enter image description here

Right now I need to do it manually one by one, which is very tedious. But I would like to color ALL the variables with the same name.

  • $\begingroup$ It is not quite clear. Do you want that the output is colored? Alternatively, you may want that the input appears colored just during the process of typing. So, what is your aim? $\endgroup$ Commented Sep 27, 2021 at 13:36
  • $\begingroup$ I want input text to be colored so the code is easier to read. I do not care about the output $\endgroup$ Commented Sep 27, 2021 at 13:47
  • $\begingroup$ In this case, I do not know the answer. Maybe, there is the possibility to introduce a color the way we introduce the bold or italic fonts (Ctrl+B and Ctrl+I) if somebody knows how to introduce the corresponding hotkeys. I do not know that. $\endgroup$ Commented Sep 27, 2021 at 14:08
  • $\begingroup$ Andris, I anticipate this can be done a number of ways, so can you, please, answer this question: Should the variable/symbol color change occur immediately upon typing the complete symbol name, or should the change occur after the cell has been evaluated (whether there is output or not should not be of concern here)? $\endgroup$ Commented Sep 27, 2021 at 14:25
  • $\begingroup$ I would favor that the color changes immediately without evaluating the cell, but if it makes the problem difficult, other option is fine as well. $\endgroup$ Commented Sep 27, 2021 at 14:43

1 Answer 1


Try some of these for formatting strategies

For indexed variables



var1/: Format[var1]:=Style["Var1",{Blue,Bold}]
var2/: Format[var2]:=Style["Var2",{Purple,Bold}]
var3/: Format[var3]:=Style["Var1",{Red,Bold}]

Change variable display



enter image description here

Or, particularly what you asked for:

enter image description here

  • $\begingroup$ @AndrisErglis, does this provide what you want? $\endgroup$
    – rhermans
    Commented Sep 28, 2021 at 9:34
  • $\begingroup$ Hi, thanks for the solution, this comes in handy. But I rather wanted my input text to be colored so that my dense code is easier to read. $\endgroup$ Commented Sep 28, 2021 at 10:00

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.