11
$\begingroup$

I downloaded Wolfram's Intro to Mathematica in Notebook format. I like to experiment as I study but you can't edit the notebooks. They are locked for some reason. So I still have to open a work notebook, taking up more room on my small screen, and my vision isn't that great.

Is there some way to unlock the notebook so I can edit it? It's a standard .nb so I figured there must be an option I can't find.

I tried Notebook Properties in Options, but it says Editable True, which is not true. And it's grayed out so you can't change it anyway.

$\endgroup$

1 Answer 1

17
$\begingroup$

I've poked around those notebooks, turns out the culprit is $CellContext`GhostCellInEmptyNotebook option in the stylesheet. No idea what it's doing, but deleting it or setting it to True turns on editing again.

Here is some code to delete it from all the notebooks in the book:

Do[
    With[{nb = NotebookOpen[file]},
        SetOptions[nb, StyleDefinitions -> DeleteCases[CurrentValue[nb, StyleDefinitions], $CellContext`GhostCellInEmptyNotebook -> _, All]];
        NotebookSave[nb, ExpandFileName[file]];
        NotebookClose[nb]
    ],
    {file, FileNames["~/Downloads/EIWL2-Notebook-Archive/*.nb"]}
]

Or better use this one, which is much faster if you simply treat the option as a string:

Do[
    Export[file, StringDelete[Import[file, "String"], ", $CellContext`GhostCellInEmptyNotebook -> False"], "String"],
    {file, FileNames["~/Downloads/EIWL2-Notebook-Archive/*.nb"]}
]
$\endgroup$
1
  • 2
    $\begingroup$ The fast option worked perfectly right off. Thanks a lot. This will save my eyes and a lot of annoyance. $\endgroup$ Commented Sep 28, 2022 at 23:50

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.