2

I don't like how initialization (or "Code") cells are formatted in notebooks, namely the grey background color and the spacing/wrapping settings. I want to make them look exactly as if they were normal input cells (other than the Dingbat). However, I need to use them to later export my notebooks as .wls files.

My best attempt so far is to set new cells to be Initialization Cells by default, using the Options inspector in the Format menu, and setting InitializationCellStyle to something different than the default "InitializationCell" value.

This is:

Format ► Options Inspector ► Global Options ► Cell Options ► Evaluation Options ► IntitializationCell = True

Format ► Options Inspector ► Global Options ► Cell Options ► Display Options ► Private Cell Options ► InitializationCellStyle = ""

This successfully makes new cells be created as Initialization Cells with the usual "Input" format. However, cells that are already formatted as "Code" cells will not fully revert to the original format (only the background color seems to revert to white).

I have also tried other values for InitializationCellStyle such as "Input", but most seem to have the same behavior. I have not been able to find documented possible values for that setting.

I have many different files that I would like to convert to the normal format without needing to copy the cells to new ones.

Is there any way to revert cells already formatted as "Code" to the original "Input" format?

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
abcd
  • 483
  • 2
  • 7

2 Answers2

2

Does:

SetOptions[
    EvaluationNotebook[],
    StyleDefinitions -> Notebook[{
        Cell[StyleData[StyleDefinitions->"Default.nb"]],
        Cell[StyleData["InitializationCell"], Background->None]
    }]
]

do what you want?

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
  • Hi Carl, thanks for the answer. It does indeed, but also I realised I need to convert them to Initialization Cells by pressing ctrl+8, instead of cmd+8 (in MacOS). I realised it was the latter what was making the spacing and wrapping settings be different (and also the font size).

    By setting the background to transparent and using ctrl+8 (not cmd+8), they are (in appearance) formatted exactly as normal cells.

    – abcd Mar 05 '22 at 12:12
2

Probably the simplest solution:

SetOptions[EvaluationNotebook[], 
 StyleDefinitions -> Notebook[{
    Cell[StyleData[StyleDefinitions -> "Default.nb"]], 
    Cell[StyleData["InitializationCell", StyleDefinitions -> StyleData["Input"]]]}]]

Strongly related:

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
  • Are there any other Style settings (other than the transparent background) that are also characteristic of Input Cells vs Code Cells? In appearance setting the background to transparent makes them look identical to the sight, but is there something hidden that still differs? – abcd Mar 05 '22 at 12:16
  • 1
    @abcd If you are speaking about "Input" vs "Code" cells, yes. But "InitializationCell" is something special. – Alexey Popkov Mar 05 '22 at 12:24
  • Is it correct to say that ctrl+8 just makes cells InitializationCell, while cmd+8 makes them additionally Code, which has further differences such as the wrapping setting? – abcd Mar 05 '22 at 12:40
  • 1
    @abcd I hadn't investigated the differences, but CurrentValue[{StyleDefinitions, "InitializationCell"}] returns information only about cell background what may be wrong. – Alexey Popkov Mar 05 '22 at 12:47