I have used many notebooks. I know how to select function and variable definitions I want to use in future (new) notebooks. How do I then set them up to be an Initialisation for new notebooks?
Asked
Active
Viewed 88 times
0
-
It is the Mathematica property. Mathematica forgets all definitions as soon as the session is closed. During the next session, one has to redefine all the definitions (including functions). One way around would be to transform cells containing functions you expect to need in the future into the InitializationCells. To make this, you 1. select the cell in question, 2. go to Menu/Cell/CellProperties/InitializationCell. Done. If you do that, during the new session, before the very first evaluation the initialization cells will be evaluated, and Mathematica will recall the functions you need. – Alexei Boulbitch Apr 20 '23 at 21:30
-
I vote to close this question as off-topic. – Alexei Boulbitch Apr 20 '23 at 21:32
-
Yes: this is how Mathematica works. When you first start it up and evaluate something, that starts the kernel, in which definitions are stored. This kernel is not saved as part of a document and is in fact shared between different Mathematica notebooks that are open at the same time (unless you have explicitly opened two kernels and set the notebooks to use different kernels). This is very important to know, because if you have defined something in the kernel using one notebook, the other notebook environment will use that definition. When you close Mathematica, the kernels disappear. – march Apr 20 '23 at 21:57
-
3Does this answer your question? Save variables values and definition. More generally, search this site for "save definition". You will find several relevant questions. – bbgodfrey Apr 20 '23 at 23:11
-
These answers do NOT answer the question I am asking: I have used many notebooks. I know how to select function and variable definitions I want to use in future (new) notebooks. How do I then set them up to be an Initialisation for new notebooks? – Peter R Jun 03 '23 at 20:22
-
1Select cell(s) and execute menu command Cell > Cell Properties > Initialization Cell. – Michael E2 Jun 03 '23 at 20:26
-
1Or maybe you want a package? Or maybe you're looking for init.m. – Michael E2 Jun 03 '23 at 20:34
1 Answers
0
The most important Shortcut, now present in vs 13 as a key, is the CellProperty / InitializationCell, Ctrl+8 on highlithed cells, or in the Cell menu.
Merge your definition cells as a group of cells with cell attribut "Initialization group".
After loading or fresh kernel start, at the first execution, the system asks if the initializations should be done first.
Roland F
- 3,534
- 1
- 2
- 10
-
I don't understand "merge a group of cells with cell attribut "Initialization group"" – Peter R Jun 03 '23 at 20:32