Automatically Use Separate Contexts for Different Notebooks
Set up notebooks so that symbols in one will not interfere with symbols in another, a technique useful for creating “scratch” notebooks for computational experiments.
Using the Menu...
In a notebook with the default context settings, new symbols are created in the Global` context:
![](Files/AutomaticallyUseSeparateContextsForDifferentNotebooks.en/1.png)
Give a second notebook a unique context so that symbols created in it will not interfere with symbols created in the first notebook. With the second notebook frontmost, choose Evaluation ▶ Notebook’s Default Context ▶ Unique to This Notebook:
![](Files/AutomaticallyUseSeparateContextsForDifferentNotebooks.en/2.png)
Symbols in the second notebook are created in a context unique to that notebook:
![](Files/AutomaticallyUseSeparateContextsForDifferentNotebooks.en/3.png)
Since Global`x in the first notebook is different than Notebook$$676$251903`x in the second, setting the value of x in the second notebook does not affect the value of x in the first:
![](Files/AutomaticallyUseSeparateContextsForDifferentNotebooks.en/4.png)
- Packages loaded in other notebooks are unavailable to notebooks with unique contexts.
Programmatically...
In a notebook with the default context settings, new symbols are created in the Global` context:
![](Files/AutomaticallyUseSeparateContextsForDifferentNotebooks.en/5.png)
Set up a second notebook so that it creates symbols in a unique context:
![](Files/AutomaticallyUseSeparateContextsForDifferentNotebooks.en/6.png)
Symbols in the second notebook are created in a context unique to that notebook:
![](Files/AutomaticallyUseSeparateContextsForDifferentNotebooks.en/7.png)
Since Global`x in the first notebook is different than Notebook$$676$251903`x in the second, setting the value of x in the second notebook does not affect the value of x in the first:
![](Files/AutomaticallyUseSeparateContextsForDifferentNotebooks.en/8.png)
- Packages loaded in other notebooks are unavailable to notebooks with unique contexts.