2

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.

  • 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? – Alexei Boulbitch Sep 27 '21 at 13:36
  • I want input text to be colored so the code is easier to read. I do not care about the output – Andris Erglis Sep 27 '21 at 13:47
  • 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. – Alexei Boulbitch Sep 27 '21 at 14:08
  • 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)? – CA Trevillian Sep 27 '21 at 14:25
  • 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. – Andris Erglis Sep 27 '21 at 14:43

1 Answers1

2

Try some of these for formatting strategies

For indexed variables

x/:Format[x[n_]]=Style[Subscript[x,n],Red];

Colour

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

Change variable display

Format[r[t_]]=\[Rho][t];
Format[r[n_][t_]]=Subscript[Stype[\[Rho],Orange],Stype[n,Green]][t];

Visuals

enter image description here

Or, particularly what you asked for:

enter image description here

rhermans
  • 36,518
  • 4
  • 57
  • 149