# How to delete an option from a notebook

The Q&A How to unset an notebook option programmatically? nearly asks the same question, but the focus there is on how to unset an option that has been given a value. I just want to undo a mistake I made by setting an option that does not exist:

SetOptions[EvaluationNotebook[], Foo -> Bar]


While the Foo -> Bar option does not seem to interfere with the working of the notebook or Mathematica, I'd like to clean up this mistake.

I'd like to keep the other notebook option settings, so copy-pasting the contents would not work exactly as I would like (a method mention in the linked Q&A). Of course I could copy the desired options, too. I'm hoping for a more straightforward solution.

(In fact, in the actual use case, the setting was some data to be stored in TaggingRules. Now the data appear twice in the notebook options, more or less; the TaggingRules version is the up-to-date one.)

• I'm not entirely sure, but doesn't setting a option to Inherited more or less do this? – Sjoerd Smit Nov 22 '19 at 22:49
• @SjoerdSmit You're suggesting that I set an option "MyData" -> Inherited and it will be deleted? I'll try it. -- Nope, it seems the option is kept, although the setting is now Inherited. – Michael E2 Nov 22 '19 at 22:50
• Yes, the option is still there, but I believe that the value Inherited more or less acts as if the option was not there in the first place. – Sjoerd Smit Nov 22 '19 at 22:58
• The whole option is inert as it is, so it makes no difference what it is set to. It's not an actual, valid notebook option. Unknown options to notebooks seem to be ignored. It's been there for months and I only just discovered it today. I'd like to get rid of it, if possible. – Michael E2 Nov 22 '19 at 23:37

You can use NotebookGet/NotebookPut. Here is a function that does this:

RemoveNotebookOption[nbobj_, rhs_]:=With[{nb = NotebookGet[nbobj]},
NotebookPut[
nb /. Notebook[c_, o___] :> Notebook[c, Sequence @@ FilterRules[{o}, Except[rhs]]],
nbobj
]
]


Let's give the evaluation notebook the option "FOO"->"BAR":

SetOptions[EvaluationNotebook[], "FOO" -> "BAR"]


Check:

Lookup[Options[EvaluationNotebook[]], "FOO"]


"BAR"

Now use RemoveNotebookOption:

RemoveNotebookOption[EvaluationNotebook[], "FOO"]


Check:

Lookup[Options[EvaluationNotebook[]], "FOO"]


Missing["KeyAbsent", "FOO"]

• Great! That works. Thanks. (Still wonder why there's not a direct way, why more people don't need it from time to time. Maybe doofuses like me who need to fix such blunders are few and far between.) – Michael E2 Nov 22 '19 at 23:45