6
$\begingroup$

Mma Version 11 already has this feature: Initalization cells are automatically shaded light grey.

This is a very useful feature and I would like to retrofit it to my older version 10.1.

On a Mma-11 installation, I took a look how this is done. There is an additional style InitializationCell in Core.nb (it is the second last one in Styles for Input and Output Cells) and the definition of this style is:

Cell[StyleData["InitializationCell"], Background->GrayLevel[0.92]]

I added such a style into my /usr/local/Wolfram/Mathematica/10.1/SystemFiles/FrontEnd/StyleSheets/Core.nb (to do so, I had first to make a copy of it under sudo to the folder of my normal work), then open the file with Mma, use OptionsInspector on the notebook level and make it editabele, then enter a cell, use Shift-Control-E to show the cell expresseion, alter it such that it becomes

Cell[StyleData["InitializationCell"], Background->GrayLevel[0.92]]

then use Shift-Control-E again to display it in the normal way (it then displays on light grey background), then make the notebook no longer editable again using OptionsInspector on the notebook level, then store it as Core1.nb to my works folder (the store item was shaded out, but store as worked) and finally after terminating Mma rename Core1.nb to Core.nb and copy it to its original place under administrative rights (throwing away the older versions of course).

Having done this, I checked Mma 10 and created an initialization cell. However, it was not shaded light grey. The highlighting mechanism of Mma11 must be something more than just an additional style in Core.nb. But what is it and how could one retrofit this feature to older versions?

$\endgroup$
2
  • $\begingroup$ a small note : A lot of people will not undertand what is "sudo". Is that important ? (Otherwise it's a very clear question) $\endgroup$
    – andre314
    Commented Sep 17, 2016 at 6:47
  • $\begingroup$ sudo is a prefix to be put in front of a command in linux such that the command is run witrh administrative privileges. The user has to be in the sudoers list in order to use this feature and in addition he has to enter the password before he actually gets administrative privileges. This mechanism makes Linux less susceptible to malicious programs. $\endgroup$ Commented Sep 17, 2016 at 7:40

1 Answer 1

5
$\begingroup$

Here is what you can do for V < 11, put that into the stylesheet of interest:

Cell[
  StyleData["Notebook"],
  Background ->  FEPrivate`If[ 
    FrontEnd`CurrentValue[EvaluationCell[], "InitializationCell"],
    GrayLevel[0.92],
    Inherited 
  ]
]

enter image description here

ps. you don't have to change so much with Core.nb just follow those steps:

$\endgroup$
4
  • $\begingroup$ Probably FEPrivate` is not needed, FE should parse it correctly to that context, but you never know so I left it. $\endgroup$
    – Kuba
    Commented Sep 17, 2016 at 12:24
  • $\begingroup$ Kuba, thanks for your answer. This requires to edit the stylesheet of the notebook first and do that for each single new nb. I am looking for a mechanism which has the feature right away for every new notebook and possibly even existing ones. I tried to change Default.nb which I have copied to $UserBaseDirectory according to your linked hint. Does it matter where I put the new style into it? I put it right under the one InputOnly in the Styles for Input and Output Cells group. It does not work.Was this the wrong place within Default.nb? What's the right place? $\endgroup$ Commented Oct 8, 2016 at 19:15
  • $\begingroup$ @AdalbertHanßen I've put in on top, restarted the MMA and it worked. Sorry don't have time for more tests atm, will try tomorrow if your problem persists. $\endgroup$
    – Kuba
    Commented Oct 9, 2016 at 10:17
  • $\begingroup$ Yes, now I have tested it: I placed Kuba's Cell[StyleData["Notebook"], Background->FEPrivateIf[FrontEndCurrentValue[EvaluationCell[], "InitializationCell"], GrayLevel[0.92], Inherited]] into a copy of Default.nb in /home/my username/.Mathematica/SystemFiles/FrontEnd/StyleSheets/Default.nb. I put it directly after where it says "inheriting base definitions from stylesheet Core.nb". It equally works for new and for existing notebooks. $\endgroup$ Commented Oct 19, 2016 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.