MathGroup Archive 2002

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

Search the Archive

RE: Problems with creating packages (formatting)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33778] RE: [mg33748] Problems with creating packages (formatting)
  • From: "David Park" <djmp at earthlink.net>
  • Date: Tue, 16 Apr 2002 03:50:28 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Mike,

The easiest way to write and maintain a package is to write it as an
ordinary Mathematica .nb notebook. Write each statement as a separate cell.
If it is a long package you can use Sections, Subsections etc and group your
usage messages and definitions. Make the cells Initialization Cells.

Then when you first save the notebook, Mathematica will ask you if you want
AutoGenerated Packages. Answer yes. Your .m package file will be created and
updated each time you save the notebook. You never have to look at or edit
the .m file. You can edit the notebook file and when you save it the new .m
file will replace the old one.

If you have a package in notebook form and you didn't use AutoGenerated
package when you first saved it, you can correct that by using Option
Inspector, choosing notebook and going to Notebook Options\File
Options\AutoGenerate Package and choosing Automatic. You should never have
to edit a .m file directly.

While we are on the topic of writing packages, here is another aspect that I
believe is often mishandled. The place to put your own packages, and
packages you are writing for other people, is AddOns\ExtraPackages\Some
Folder. Some Folder can mirror the folder names in StandardPackages or it
could be a special name for some special topic. Say you have written a
Grassmann algebra package. You could name the notebook file Grassman.nb. You
could put it in the folder AddOns\ExtraPackages\Algebra. Make the
BeginPackage statement

BeginPackage["Algebra`Grassmann`"]

Then the package will load and behave just like a standard package. You can
load it with

Needs["Algebra`Grassmann`"]

Mathematica automatically looks in ExtraPackages when evaluating the Needs
statement.

That is the easy way of doing it.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


> From: Mike Varney [mailto:varney at colorado.edu]
To: mathgroup at smc.vnet.net
>
> Hello all.
>
> I am attempting to create a package under version 4.1.
> After entering in my functions, etc etc and setting the cell as the
> initiation cell, I am able to save the package as package.m.
>
> I can now call and load the package fine and the functions work fine as
> well.
>
> The problem is that when I open package.m in mathmatica to edit
> the package
> the text is in the "plain text" format, i.e..
>
> F[x_] := Cos[x]^3 + 3Exp[x]+1
>
> Becomes:
>
> \!\(F[x_] := Cos[x]\^3 + 3  Exp[x] + 1\)
>
> The installation is the default one with an extra directory under
> standardpackages for my packages.  I have changed none of the default
> settings.
>
> My saving procedure is the following:
>
> 1.  I click on a cell and type in my functions, etc to create the package.
> This includes comments, etc., etc.
>
> 2.  I click on the cell bracket and choose Cell -> Cell Properties ->
> Initialization Cell
>
> 3.  I save as special -> Package Format
>
> I close the notebook without saving, restart mathematica and open the
> package.m and see the formatting errors.
>
> If any of you have ideas on how to solve this I would appreciate the
> feedback.
>
> Thanks.
>
> Mike
>
>



  • Prev by Date: RE: RE: How to Return from within a Table[]-Command?
  • Next by Date: Re: Optional
  • Previous by thread: Problems with creating packages (formatting)
  • Next by thread: Re: Problems with creating packages (formatting)