# Detection of the text color

Is it possible to detect the text color in Mathematica, so that a command like this:

TextColor[<colored text>]


would return the color of the text in some way?

For example, when I input

G[m_] := Module[{k}, 4]


Mathematica colors m_ and k some greenish color(s). I'd like to know precisely what those colors are.

• How was the text coloured? Provide code that colours the text or at the very least the source of the coloured text. – Edmund Apr 28 '17 at 1:20
• @Edmund : I have added an example of such code. – Iosif Pinelis Apr 28 '17 at 1:27
• does this give what you need: textColor[x_] := Cases[x, _?ColorQ]? – kglr Apr 28 '17 at 1:35
• @kglr : I am not sure how to use this. When I input textColor[Module[{k}, 4]] I get {}. F1 yields "ColorQ[color] yields True if color is a valid color directive and False otherwise". – Iosif Pinelis Apr 28 '17 at 2:01

These styles are controlled by the AutoStyleOptions setting of a Cell:

oldLVS=CurrentValue[{AutoStyleOptions,"LocalVariableStyle",FontColor}]
oldPVS=CurrentValue[{AutoStyleOptions,"PatternVariableStyle",FontColor}]


RGBColor[0.263, 0.537, 0.345]

RGBColor[0.263, 0.537, 0.345]

Let's change these colors to Red and Blue:

CurrentValue[$FrontEndSession,{AutoStyleOptions,"LocalVariableStyle", FontColor}]=Red; CurrentValue[$FrontEndSession,{AutoStyleOptions,"PatternVariableStyle", FontColor}]=Blue;


And, you should see that the variables are colored red and blue now:

Finally, return the colors to their old values:

CurrentValue[$FrontEndSession,{AutoStyleOptions,"LocalVariableStyle", FontColor}]=oldLVS; CurrentValue[$FrontEndSession,{AutoStyleOptions,"PatternVariableStyle", FontColor}]=oldPVS;

• How to know the other items except "LocalVariableStyle" and "PatternVariableStyle"? – yode Apr 28 '17 at 2:15
• Options[Cell, AutoStyleOptions] – Carl Woll Apr 28 '17 at 2:16