Message Boards Message Boards

Notebook Independence from a new Mathematica User.


I've started a Notebook, and after digging myself deeper and deeper into a hole, I decide to start all over again, so I close the notebook,WITHOUT SAVING and start a new notebook. But Mathematica is smarter than me - it remembers what I did in the closed Notebook (that I did not save !) and keeps going, by numbering all my "In"'s and "Out"'s from where I left off.

I can close the kernel and restart it, but surely there has to be  a way to start a new notebook with a clean slate. Can't find the answer in the "help" or the manuals, or any of the preferences, although most of those make no sense (to me) anyway.

Can someone please tell me how to create a new notebook that doesn't remember what has gone before?

Thank you in advance.
POSTED BY: Michael Milgram
5 years ago
Try ClearAll[]
POSTED BY: George Hrabovsky
5 years ago
Despite the name, ClearAll does not clear "all variables".  It clears all definitions associated with particular symbols.The normal clear command clears values and function definitions, but it does clear attributes, formatting information, or messages.  That's what ClearAll is for.

However, all these commands accept name patterns. So one way to "start fresh at will" is to evaluate
POSTED BY: Itai Seggev
5 years ago
You've got to learn the "notebook way" with shared kernels, as opposed to "script based programming", but I'm not going to lecture you. Sometimes, the journey to the proper usage is worth it emoticon

For now, here's what to do. Open the file at
FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]
in a text editor, add the following lines and save it.
 MyInit`NewNotebook[] := Block[{},
     $HistoryLength = 0;
     $Line = 0;
 $ContextPath = Append[$ContextPath,"MyInit`"];

Now restart Mathematica. When you want a new notebook, just run NewNotebook[] and have fun emoticon
POSTED BY: John Q. Public
5 years ago
You may find it convenient to use a different context for each notebook, i.e. symbols defined in one notebook will not appear in another notebook. You can find this option in the menubar under Evaluation -> Notebook's Default Context -> Unique to this Notebook.

This can be achieved programmatically with the following,
SetOptions[EvaluationNotebook[], CellContext -> Notebook]

And undone with:
SetOptions[EvaluationNotebook[], CellContext -> "Global`"]
POSTED BY: Martin Hadley
5 years ago
You can also apply Martin Hadley's suggested CellContext option setting at the global frontend session level:
SetOptions[$FrontEnd, CellContext -> Notebook]

With this setting all newly created notebooks will have their own unique context for the symbols within them:
In[1]:= a = 2;

In[2]:= Context[a]
Out[2]= "Notebook$$24$265933`"

This way you can have multiple notebooks, each with their own symbol definitions.

Setting this option also causes the input/output numbering to start at In[1] for every new notebook.

With this option, keep in mind that you are still working in the same global kernel session, which means that all expressions used in all notebooks are still in memory (even if you closed a notebook). So if you did,

and then closed that notebook, the kernel will still have a reference to that symbol 'a' in some Notebook$$nn$mmmmm` context.
POSTED BY: Arnoud Buzing
5 years ago

Group Abstract Group Abstract