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.
Answer
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.
.
Comments
Post a Comment