14

I have a neurological disorder which causes me to have migraines if I look at a white computer screen. To combat this, I have put the following at the top of all of my Mathematica notebooks:

SetOptions[EvaluationNotebook[],
Background -> RGBColor[0.0, 0.0, 0.0],
FontColor -> RGBColor[1.0, 1.0, 1.0],
FontSize -> 16
]

This turns the background black and the letters white. However, Mathematica's built-in Syntax highlighting does not change. In order to read the Syntax Highlighing I have to manually go into:

In Edit -> Preferences -> Syntax Coloring -> Other:

  • Comments -> Megenta
  • Strings -> Light Yellow
  • Global -> Bright Blue

In Edit -> Preferences -> Syntax Coloring -> Local Variables;

  • The local variables of Module With -> Bright Green;
  • Function arguments and patter names -> Bright Green;
  • Variables made special by use in arguments -> Sky Blue;

The above commands permanently change the syntax highlighting. If possible, I would like to be able make the above changes in the Mathematica Notebook so that the changes only affect the notebook I am working in. So, my question is...

QUESTION: Rather than do the above steps manually, is there a command I can put at the top of the file that will make these changes for me?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
user26807
  • 163
  • 7
  • 2
    You can create a stylesheet with your preferred colors and then apply it to individual notebooks (or set it for all notebooks). See my answer here that should show you the way. There's no one-step solution; there's some effort involved, but it'll be one time. I personally do most of my Mathematica programming in vim, which allows me to use my favourite theme (it looks like this). – rm -rf Apr 02 '13 at 17:05
  • 1
    I also once made a half-complete port of the solarized theme to a Mathematica stylesheet. The nice thing about solarized (there are a few others like this) is that you can keep the colors the same and simply switch the background from light to dark and it still looks good. You can try downloading that and changing the background colors and text to suit your needs (if that theme is to your tastes). If I find some time later today, I'll perhaps do that, if you haven't done so yourself by then. – rm -rf Apr 02 '13 at 17:05
  • 1
    @rm-rf You have a very nice color scheme, it seems. I have played with the color schemes in WB, but my current one is not as nice. – Leonid Shifrin Apr 02 '13 at 17:09
  • @LeonidShifrin That's the solarized dark palette (it's available for WB too), but the vim syntax highlighting (which is up-to-date for system functions in v9.0.1) is my own plugin and so are the choice of colors. I have the same in WB too, if you want it I can export my settings (I'll have to figure out how first), but I'm not sure if I can export just the colorscheme alone (lest the rest overrides yours) – rm -rf Apr 02 '13 at 17:13
  • @rm-rf If you could export those, that would be nice. You do it by File -> Export -> General -> Preferences. Don't worry about exporting color settings only - I am used to work with the settings file, so I can figure out the color part on my own and update my settings. There is no hurry with this, anyway. Thanks :). – Leonid Shifrin Apr 02 '13 at 17:17
  • @rm-rf. Thank you for the link. I wonder though, rather than create a style sheet, is there any way to simply add commands directly in a matehmatica notebook (as I have above for Background, FontColor and FontSize)? – user26807 Apr 02 '13 at 17:38
  • If you have a Macintosh, have you tried Control+Option+Command+8 ? This toggles the colors of all syntax, including strings, comments and global. More information here (http://www.cultofmac.com/79252/100-tips-46-invert-your-macs-display-colors/). – DavidC Apr 02 '13 at 18:17
  • @user26807 Sure, it's possible. See Mike's answer for an example (the second code block). Essentially, you do SetOptions[EvaluationNotebook[], StyleDefinitions -> Notebook[styles you want to add go here]]. Again, as I said earlier, it's not a simple option that can be switched on/off. The effort that goes into writing that is the same as that to make a stylesheet (I prefer the latter). – rm -rf Apr 02 '13 at 18:20
  • @rm-rf: I see. Thank you very much for you help. – user26807 Apr 02 '13 at 18:31

1 Answers1

16

You can do this using the following code:

CurrentValue[EvaluationNotebook[], 
   {AutoStyleOptions, "UndefinedSymbolStyle"}] = {FontColor -> RGBColor[0.5`, 0.173`, 0.765`]}

More style options (other than "UndefinedSymbolStyle") that can be set are:

{"CommentStyle", "EmphasizedSyntaxErrorStyle", "ExcessArgumentStyle", 
"FormattingErrorStyle", "FunctionLocalVariableStyle", 
"FunctionNotebookStyle", "GlobalSymbolStyle", 
"GlobalToLocalScopeConflictStyle", 
"GraphicsCompatibilityProblemStyle", "LocalScopeConflictStyle", 
"LocalVariableStyle", "MissingArgumentStyle", 
"MissingArgumentTemplateStyle", "MisspelledWordStyle", 
"NoKernelPresentStyle", "OrderOfEvaluationConflictStyle", 
"PatternVariableStyle", "StringStyle", "SymbolContextStyles", 
"SymbolShadowingStyle", "SyntaxErrorStyle", "UndefinedSymbolStyle", 
"UnknownOptionStyle", "UnwantedAssignmentStyle"}

You can check the current settings with:

Options[EvaluationNotebook[], AutoStyleOptions]
Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323