MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Can you get a package back to a notebook easily?

  • To: mathgroup at
  • Subject: [mg83074] Re: [mg83032] Re: Can you get a package back to a notebook easily?
  • From: Murray Eisenberg <murray at>
  • Date: Fri, 9 Nov 2007 05:20:04 -0500 (EST)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <fgen3e$flh$> <fgs7k8$3gb$> <>
  • Reply-to: murray at

1. Converting notebook to a package.

    This assumes you've written code in the notebook that includes the
appropriate extra stuff for good package functionality...


    ThisFunc::usage="describe thisFunc";
    ThatFunc::usage="How to use thatFunc";

    (* definitions of objects here *)



All these cells (except possibly comments), but not text cells, should
be made, by the Cell > Properties menu item, into Initialization Cells
that are Active.

Save the notebook with name pkgName.nb.  When asked if you want to
automatically save this as a package, too, answer yes.  Automatically,
wherever the notebook MyNB.nb is saved, you'll get the corresponding
pkgName.m package file in the same directory.

2. Move (or copy) both the .nb file and the .m file into a subdirectory, 
named topName, of InstallationDir\AddOns\Applications\  (where
InstallationDir refers to the top-level directory of the Mathematica
tree -- the value of the Mathematica system variable $InstallationDirectory.

That's it.

When you want to revise the package, revise the "auto-save" notebook you 
thereby created in step 1, and when you save the notebook, it will
automatically update the package accordingly.

3. To use the package,




Re Step 2, of course you can keep a copy of the original saved notebook
and auto-saved package .m file elsewhere and work on revisions there
before moving the new versions as explained in Step 2.

This is just a brief (and, I hope, entirely correct) outline of a
process that has many variants, e.g., with respect to where you may put
packages, or how to make packages load automatically whenever you open

AES wrote:
> In article <fgs7k8$3gb$1 at>,
>  Szabolcs Horv=E1t <szhorvat at> wrote:
>> David Reiss wrote:
>>> Actually, in Version 6+ the answer is no.
>>> The initialization cells are saved, and some other classes of cells
>>> are contained as comments with special information that allows them to
>>> still be viewed when the .m file opened in Mathematica.
>>> Try it out and then open the .m file in a text editor to see this...
>> Can you give an example?  Before I replied, I tried it with a notebook
>> that only had input cells and text cells.  Only the initialization input
>> cells were saved.
>> Szabolcs
> Or better, after developing and testing in notebook form a lengthy
> module that I want to convert to package form, I'd like to have a
> specific set of instructions on how to:
> * Convert the notebook to a package
> * Save/install the package  [To where? And how?]
> * Save/preserve the notebook also [Where? And how?]
> so that I can when needed, edit or modify the original notebook and
> repeat the process.
> The problem is not so much "how to write a package"; it's finding, all 
> in one place, the above specific instructions on how to manage it

Murray Eisenberg                     murray at
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

  • Prev by Date: Re: machine precision number plot fixed in V6?
  • Next by Date: Re: affine transformation to rasters
  • Previous by thread: Re: Can you get a package back to a notebook easily?
  • Next by thread: Re: Can you get a package back to a notebook easily?