according to the documentation at ref/InitializationCell,

When you first save a notebook that contains initialization cells, you have the option to make a parallel auto-generated .m package that contains only the contents of the initialization cells. The package is by default automatically updated whenever the initialization cells in the notebook are changed and saved again.

This would be a REALLY NICE feature, because it would give me a beautiful way to document a package in a notebook (instead of just textual code)!

To test it out, I took the documentation a bit literally and created a new notebook with a single initialization cell (with the little vertical-hook cell-bracket initialization-cell giveaway highlighted in yellow and circled in red in the screenshot, here:

enter image description here

The cell after the initialization cell is supposed to be just a reference to the initialization cell, and, when I evaluate the notebook, voila, there is the expected value.

However, when I now save the notebook, I don't get the advertised "option to make a parallel auto-generated .m package." Ok, so I make one manually (Save As.../Save As Type.../Mathematica Package .m), no problem, as follows:

enter image description here

But, of course, this one is not "automatically updated whenever the initialization cells in the notebook are changed and saved again." Here's the updated notebook:

enter image description here

but the .m file is not automatically updated. I would use this feature daily if I could get it to work. As always, I'll be very grateful for advice, guidance, clues.


This may be set from the Option Inspector (Format->Option Inspector) from this option:

enter image description here

Automatic automatically creates a package.

(to be clear, you need to select Global Preferences for this to apply to all your notebooks).

  • 11
    $\begingroup$ I'd suggest setting it to Manual. If you set it to Automatic, it will automatically create the package every time. If you set it to Manual, it will explicitly ask whether the package should be created the first time the notebook is saved. If it is set to None, it will never create the package. $\endgroup$ – Szabolcs Feb 5 '12 at 18:45
  • $\begingroup$ Is there something similar for scripts? mathematica.stackexchange.com/q/170420/534 $\endgroup$ – becko Apr 4 '18 at 15:54

In case you do not want it to apply for all notebooks (which I prefer), you could put an additional line somewhere in your notebook:

SetOptions[InputNotebook[], AutoGeneratedPackage -> Automatic]


SetOptions[InputNotebook[], AutoGeneratedPackage -> Manual]
  • $\begingroup$ Hi Rolf. Do you know if it's ok to use this? I liked it a lot but the documentation says: "This function has not been fully integrated into the long-term Mathematica system, and is subject to change.". $\endgroup$ – Murta Feb 24 '13 at 18:29
  • $\begingroup$ Hi Murta. Probably ok. There are only 279 such "not fully integrated" itmes. I doubt that those get ever really deleted. This gives you a list: nlt = FileNameTake /@ Select[ Select[FileNames["*.nb", $TopDirectory, 99], StringMatchQ[#, "*ReferencePages*"] &], FindList[#, "has not been fully integrated into the long-term"] =!= {} &]; $\endgroup$ – Rolf Mertig Feb 24 '13 at 20:17
  • $\begingroup$ Nice way to scrap documentations. Tks! $\endgroup$ – Murta Feb 24 '13 at 20:31
  • $\begingroup$ Length[nlt] gives 247 for Mathematica 10.1. So 30 more! $\endgroup$ – Rolf Mertig Jun 16 '15 at 3:03
  • 1
    $\begingroup$ @tchronis Not directly, but you can use Wolfram Workbench to format the code. Though I really think complicated programming should not be done in notebooks, but directly in Workbench or the IntelliJ plugin. $\endgroup$ – Rolf Mertig Nov 14 '16 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.