# Syntax highlighting conflict

I'm trying to syntax highlight this expression: x=$\sqrt{\pi }$//N and from various sources I've learned that x (the assigned symbol) belongs to context Global while the Pi and N belongs to System. So I set out to change the style of both using a hodgepodge of tips I gleaned from this StackExchange as well as from StackOverflow.

However, the weird thing is that the style changes do not add to each other. If I change the style of System, any previous style change to Global would be wiped away, and vice versa. In other words, I can have syntax highlighting for either System, or Global, but not both. This could be seen from these screenshots (sorry for the small font, code added):

First line:

SetOptions[$FrontEndSession, "AutoStyleOptions" -> {"SymbolContextStyles" -> {"System" -> RGBColor[211./255, 54./255, 130./255]}}] (*magenta*)  Setting System style: magenta Second line: SetOptions[$FrontEndSession,
"AutoStyleOptions" -> {"SymbolContextStyles" -> {"Global" ->
RGBColor[181./255, 137./255, 0./255]}}] (*yellow*)


Setting Global style: yellow; when evaluated, previously set System style was wiped out

Could anyone guide me toward getting syntax highlighting for both of them? I really hope MMA has better syntax highlighting on their future releases.

-
BTW I got the RGB color from the Solarized theme here: zovirl.com/2011/07/22/solarized_cheat_sheet –  seismatica Jun 1 at 7:39
Since no one has mentioned it, you can set this option for the "Input" style by editing the stylesheet. Enter/choose the Input style, select the cell, use menu command Edit > Show Expression, and add the option so that the cell expression looks like this: Cell[StyleData["Input"], AutoStyleOptions->{"SymbolContextStyles"->{"System" -> RGBColor[211./255, 54./255, 130./255], "Global" -> RGBColor[181./255, 137./255, 0./255], Automatic -> {}}}]. Then the style will persist from session to session. –  Michael E2 Jun 23 at 0:35

To prevent your second invocation of SetOptions from resetting the value of sub-option "SymbolContextStyles", you need to set both "System" and "Global" sub-sub-option values at once:

SetOptions[EvaluationNotebook[],
"AutoStyleOptions" -> {"SymbolContextStyles" ->
{"System" -> RGBColor[211./255, 54./255, 130./255],
"Global" -> RGBColor[181./255, 137./255, 0./255]}}]


Note: Replace EvaluationNotebook[] with $FrontEndSession to make the new setting effective for all notebooks in the current MMA session, and with $FrontEnd to make them apply to current and later sessions.

This setting works as expected on my Windows 8 (64bit) system with Version 9.0.1.0.

.

-
OMG you don't know how happy you're making me right now! I wanna kiss you! –  seismatica May 31 at 19:52
@seismatica, glad it made you so happy.. –  kguler May 31 at 20:04
Just one comment for those who are trying to follow this: use EvaluationNotebook[] if you want to apply the highlighting to your current notebook. Replace it with FrontEndSession (with a dollar sign in front--I can't type the dollar sign without messing up the formatting of the comment*) to apply to currently opened notebooks, or FrontEnd (with a dollar sign in front) for all notebooks from then on. That's what my understanding of this is. Please correct me if I'm wrong in any part. *Also see the code in my question. –  seismatica Jun 1 at 7:44
@seismatica, good point. Just added a note in the post. –  kguler Jun 1 at 9:12
The docs have material on CurrentValue, SetOptions, $FrontEndSession, and the like. Options is a sparsely charted - and expanding - territory. My main source for undocumented or rare functions or options is this site and random exploration of the links in this Q/A. – kguler Jun 1 at 13:09 Note that while the accepted answer obviously answers the question it is also possible to set values of System and Global individually. CurrentValue[EvaluationNotebook[], {"AutoStyleOptions", "SymbolContextStyles"}] (* {"System" -> {}, "Global" -> {}, Automatic -> {}} *)  So to set only System: CurrentValue[EvaluationNotebook[], {"AutoStyleOptions", "SymbolContextStyles", "System"}] = Orange  And to set only Global: CurrentValue[EvaluationNotebook[], {"AutoStyleOptions", "SymbolContextStyles", "Global"}] = Green  Use EvaluationNotebook[], FrontEnd, or $FrontEndSession as required as per discussion above.

-
Thank you so much for this as well; it shows the error that I made to set SymbolContextStyles to just contain System or Global. I have a question: when you use CurrentValue on the EvaluationNotebook, what exactly is {"AutoStyleOptions", "SymbolContextStyles"} supposed to return? Is SymbolContextStyles a subset of AutoStyleOptions? I've been trying to find detailed documentation on this to no avail, so I'd love it if you could tell us where you learned about all this. PS: I checked out your website and was very impressed by all the front-end stuff. I hope I could reach that level one day. –  seismatica Jun 1 at 12:09
@seismatica the best place to see how these syntax options are nested is to go to the options inspector and search for e.g. "AutoStyleOptions" and you will see that SymbolContextStyles is a subset. –  Mike Honeychurch Jun 1 at 22:07