> How do I set up MMA to initialize a .nb when I load it. When I save a .nb and the exit MMA, and then restart and reload the .nb, I'm not in the same environment. I.e., loading of add-ons and function definitions are forgotten. I find I have to reload Statistics each time, and re-execute function definitions. Is there some way to keep the environment (Context?) between sessions?
> Thanks. Thomas
You can mark the cells you wish to have evaluated on startup as initialization cells using Cell | Cell Properties. Once you do that, you will have several options:
- When you save the file you will have the option to create an AutoSave package which will be a companion package to your notebook which can be loaded using Get or Needs (you may have to attend to the location of the file to make sure that location is in $Path). The AutoSave package will be updated each time you save your notebook changes to reflect the initialization cells that are in the notebook.
- If you do not create the AutoSave package you can evaluate the initialization
cells after opening by evaluating the first one and then responding to the
dialog that asks if you wish to evaluate all the initialization cells.
You can also change the behavior of the FrontEnd so that initialization cells
are automatically evaluated when you open the notebook by changing the option
Notebook Options | Evaluation Options | InitializationCellLoading to True.
You can also turn off the dialog by changing the option,
Notebook Options | Evaluation Options | InitializationCellLoading to False