Message Boards Message Boards

9 Replies
13 Total Likes
View groups...
Share this post:

Notebook independence from a new Mathematica user.

Posted 11 years ago

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
9 Replies

When you closed your notebook without saving did you have another notebook open? Or a Help page? Closing a notebook is not the same as closing a Mathematica Session. If you want to start over then close everything and start a new Session.

I just did two tests. I brought up an existing notebook, evaluated it and noted the last In/Out numbers. (50, 51, 52). In one test I saved it and closed it. In the other test I didn't save it before closing. These actions ended the Mathematica Session. I then started a new notebook and typed the statement 1+1 and evaluated it. In both cases the In/Out numbers were (1,2).

When I do development in a notebook I always use Sectional organization. Then if I end up in a rabbit hole I just start a new Section and delete the old Section and continue with the same notebook. Often I still want to copy over from the old Section. Sometimes I name them Try 1 and Try 2.

Another possibility for clearing out definitions is to use the old package CleanSlate by Todd Gayley. See:

POSTED BY: Murray Eisenberg
Posted 3 years ago

Same answer as Arnoud Buzing

Another way is to go to "Preferences" -> "Advanced" -> "Open Option Inspector".

Search for CellContext and set the option from "Global" to "Notebook" enter image description here

Posted 8 days ago

To clear up a point of confusion for me. The default value is "Global`". We are changing it to Notebook without " or .

POSTED BY: Updating Name
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
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
Posted 11 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
Try ClearAll[]
POSTED BY: George Hrabovsky
Posted 11 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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract