# How to unset an notebook option programmatically?

This question is related, but not identical, to this one.

Suppose one sets a notebook option like this

SetOptions[EvaluationNotebook[], Foo->Bar];


...and subsequently one wants to unset this option. Just a straightforward undoing of a previous setting, so that the setting of the option is just as it was before the SetOptions command above was issued.

How to do this?

One thing not to do is to make use of Format > Option Inspector.... Avoid at all cost. Either it's totally broken, or it is so counterintuitive that it may as well be broken.

The only solution I have found is to copy the contents of the fouled-up notebook to a fresh notebook, and overwrite the former with the latter; i.e.:

1. Ctrl+A (Edit > Select All)
2. Ctrl+C (Edit > Copy)
3. Ctrl+N (File > New)
4. Ctrl+V (Edit > Paste)
5. select original notebook
6. Ctrl+W (File > Close)
7. Ctrl+S (File > Save); overwrite original notebook by saving the notebook created in (3) to the original notebook's path

Of course, it's almost obscene to call this a "solution".

Is there some other way to return a notebook option to the setting it had when it was created?

• Could you give an example of a real option you are trying to set / unset? – MarcoB Jun 7 '15 at 18:55
• Also, depending on the option, it may work to set the value of the option to Inherited. The documentation states that, when you set a value to Inherited, "If no explicit setting is given at any level, then a built-in default value is used. " – MarcoB Jun 7 '15 at 19:00
• @MarcoB: The option I was trying to unset was CellContext (which I had set to Notebook). BTW, Inherited seems to do the trick for CellContext at least. I think this would make a suitable answer, if you care to post it. – kjo Jun 7 '15 at 19:11

## 1 Answer

Following up on my comment, and depending on the exact option whose value you are trying to unset, it may work to set the value of that option to Inherited.

In fact, the documentation states that when you set a value to Inherited, "If no explicit setting is given at any level, then a built-in default value is used" (from the second bullet point in the "Details" section of the documentation page on Inherited).

This seems to work in the OP's case for the CellContext option, and a few other options I tried. As another example, options such as e.g. WindowSize for the current notebook:

Options[EvaluationNotebook[]]

SetOptions[EvaluationNotebook[], WindowSize -> {600, 600}]
Options[EvaluationNotebook[]]

SetOptions[EvaluationNotebook[], WindowSize -> Inherited]
Options[EvaluationNotebook[]]