MathGroup Archive 2005

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

Search the Archive

Re: New Mathematica menu: New Package

  • To: mathgroup at
  • Subject: [mg57143] Re: New Mathematica menu: New Package
  • From: David Bailey <dave at>
  • Date: Thu, 19 May 2005 03:08:10 -0400 (EDT)
  • References: <d5mvks$e3d$> <> <d5sjbl$nml$>
  • Sender: owner-wri-mathgroup at

Zhengji Li wrote:
> Actually, I have already suffered a lot from modifying
> What I want to do is just a singal click, and get a new file of which
> the first cell is the "InitializationCell" and in "InputForm".
> On 5/10/05, David Bailey <dave at> wrote:
>>Zhengji Li wrote:
>>>Dear all,
>>>    It seems to be very difficult to create/save a package file from
>>>the menu of mathematica. But mathematica's main menu is
>>>"programmable", so I would like
>>>to insert a menu item which can create a .m file. Anyone need this ?
>>>   Modify in the directory (on Windows, I do not know what it is on
>>>Mac, etc) $InstallDir\SystemFiles\FrontEnd\TextResources\Windows:
>>>      Menu["&File",
>>>      {       Menu["&New",
>>>              {
>>>                  Item["&Notebook", "New", MenuKey["n", Modifiers->{Control}]],
>>>                  Item["&Package", KernelExecute[
>>>                    NotebookWrite[NotebookCreate[WindowTitle -> "Untitled.m"],
>>>                            Cell["(* Title: *)\n\n(* Author: *)\n\n(*
>>>Content: *)\n\n(* Keywords: *)\n\n(* Version:
>>>                             "Input",
>>>                             PageWidth->Infinity,
>>>                                InitializationCell->True,
>>>                                ShowSpecialCharacters->False,
>>>                                FormatType->InputForm
>>>                                                       ]
>>>                                               ]
>>>                                       ], MenuEvaluator->Automatic
>>>                  ]
>>>              }],
>>>             ..... other File menu items
>>>   The magic here is to "MenuEvaluator->Automatic" to let the kernel
>>>execute the command.
>>>   Best regards.
>>I too like to extend the menu system, however you don't need to go to
>>such trouble to create packages - just set the package up in a notebook
>>with the relevant cells marked as 'Initialization cells' and use the
>>AutoGeneratedPackage option.
>>Anyone modifying the file should be careful to close
>>Mathematica and take a copy of the file first. Mathematica only reads
>>this file as it starts up, and  if it finds an error, it just gives up
>>with a pretty un-informative message - so beware!
>>David Bailey
The code you need to execute is:

Module[{nb = NotebookCreate[]},
     NotebookWrite[nb, Cell[BoxData[""], "Input", InitializationCell -> 

If I were you, I would set that up as a function and pre-load it by 
adding a Get of the relevant .m file in your init.m file in the 
configuration/kernel subdirectory. That can be useful for all kinds
of stuff that you would like to pre-load every time you start Mathematica.

Altering is tricky, but if you keep a backup and then alter
it in stages it is feasible. Note in particular, that some operators 
must be spelled out in full if inserted in this file (e.g. = must be 
replaced by Set). At any rate, it is easier to call one function defined 
elsewhere than to attempt to insert large chunks of Mathematica code 
into the file. Alternatively, you could make a palette to 
call your new function.

David Bailey

  • Prev by Date: NonLinearRegress and constraint parameters
  • Next by Date: Re: UpSetDelayed and N
  • Previous by thread: Re: Re: New Mathematica menu: New Package
  • Next by thread: Adding two numbers of high precision results in a number of low precision??