Hongyi,
Only Initialization
cells are saved to the wl
file as uncommented code. Add the Initialization Cell
property to the cells you want to export as code. From the menu Cell / Cell Properties / Initialization Cell. On a Mac the shortcut is Control 8.
You could also add the following to the notebook
SetOptions[EvaluationNotebook[], AutoGeneratedPackage -> Automatic]
After evaluating it, whenever the notebook is saved a corresponding .m
file is created for all Initialization
cells. I often put expressions that are used in many different projects into such a notebook and use Get
to use the expressions in the .m
file in another notebook.