此为 Mathematica 7 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.1)
Mathematica HowTo
How to | Work with Initialization Cells
Using initialization cells, you can specify that particular input cells of a notebook should be evaluated first. This ensures that your code is evaluated in the correct order, such as defining functions before you might evaluate cells that use those definitions.
This is a selection of examples from the complete 'How to' screencast »
To create an initialization cell, select the cell bracket of the cell containing your initialization code and choose CellCell PropertiesInitialization Cell.
The cell bracket will now include a short vertical tick mark:
In[1]:=
Click for copyable input
After saving and reopening your notebook, when you evaluate any cell in the notebook you will be asked if you want to automatically evaluate all the initialization cells in the notebook.
    
You can also create initialization cells by using the "Code" cell style (FormatStyleCode or DynamicBox[ToBoxes[If[$OperatingSystem === MacOSX, Cmd, Alt], StandardForm], ImageSizeCache -> {30., {1., 10.}}]+8):
f[x_]:=x{2}+x+1