How to Create a Mathematica 6.0 Add-On with Documentation in the "Documentation Center" (Help Menu) and Palette in the "Palettes" Menu

Author: Jose Luis Gomez-Munoz
http://homepage.cem.itesm.mx/lgomez

Contents

Create a package that can be loaded with Needs[ ]

Create package's documentation in Mathematica's "Documentation Center" (Help Menu)

Create a palette for the package and place it in the Palettes menu

Distribute your Add-on to other Mathematica users

Create a package that can be loaded with Needs[ ]

Mathematica's Add-ons must be placed in special directories (folders), either the $BaseDirectory or the $UserBaseDirectory. These directories are different in each computer. Evaluate $UserBaseDirectory in your Mathematica session, the actual result in your computer will be different from the one shown:

"createMathematica6AddOn_1.gif"

"createMathematica6AddOn_2.gif"

The new Mathematica Add-on will be placed inside the "Applications" subdirectory (folder) in the $UserBaseDirectory (remember that in your computer it will be a different directory, the one that you obtain from evaluating $UserBaseDirectory in your computer):

"createMathematica6AddOn_3.gif"

Write a Mathematica package. You can do that in Mathematica (File Menu, New option, Package option):

"createMathematica6AddOn_4.gif"

Here is the sample package that will be used in the rest of this document:

"createMathematica6AddOn_5.gif"

Here you have the sample package, so that you can copy-paste to the package editor:

BeginPackage["Plots`TwoD`"]

PlotColor::usage=
"PlotColor has the same sintaxis as Plot"<>
" and you can change the color in real time";

Begin["`Private`"]

PlotColor[f_, {x_,x1_,x2_}, opts___Rule]:=
Manipulate[
     Plot[f,{x,x1,x2},PlotStyle->Hue[c],opts],
{{c,0.8,"Color"},0,1}];

End[]
EndPackage[]

The argument of the command BeginPackage is called Context, and it specifies the subdirectory and filename that the package must have, separated by a backquote and finishing with another backquote:

"createMathematica6AddOn_6.gif"

Create the subdirectory Plots inside Applications and save there the package with the filename TwoD and the extension .m. Remember that Mathematica is case sensitive:

"createMathematica6AddOn_7.gif"

Close the file TwoD.m
If everything is alright, then you can load the package with the Needs["Plots`TwoD`"] command, then see the new commands with the Names["Plots`TwoD`*"] command  and use those new commands (in this example there is only one new command):

"createMathematica6AddOn_8.gif"

"createMathematica6AddOn_9.gif"

"createMathematica6AddOn_10.gif"

"createMathematica6AddOn_11.gif"

"createMathematica6AddOn_12.gif"

"createMathematica6AddOn_13.gif"

Now our package can be loaded with the Needs[ ] command, in the same way as the standard Mathematica Add-ons. In the following section we will create a help file for our package and we will include it in Mathematica's "Documentation Center" (Help Menu).

Contents

Create package's documentation in Mathematica's "Documentation Center" (Help Menu).

Now we will create documentation for the package we just created, and we will include that documentation in Mathematica's "Documentation Center" (Help Menu). In a new Mathematica file (notebook) write a title, for example "Basic Example", and select the title cell with the mouse:

"createMathematica6AddOn_14.gif"

With the Cell selected, press the "Format" menu, "Style" submenu and select "Title":

"createMathematica6AddOn_15.gif"

Below the title cell write other cells with the commands for this basic example:

"createMathematica6AddOn_16.gif"

Inside the package directory (Plots) create another directory with name Documentation. Inside that directory create another directory with name English. Inside that directory create another directory with name Guides. Finally inside that inner directory save the Mathematica file with the name PlotsDocumentation.nb. Remember that all this directory structure is inside the Applications subdirectory of the $UserBaseDirectory, as you can see in this image:

"createMathematica6AddOn_17.gif"

Create another file with the format of a package (File Menu, New option, Package option):

"createMathematica6AddOn_18.gif"

Write the following text inside that new file the following text:

"createMathematica6AddOn_19.gif"

Here you have the sample package, so that you can copy-paste to the package editor:

(* Paclet Info File *)
Paclet[
     Name -> "Plots",
     Version -> "1.0.0",
     MathematicaVersion -> "",
     Description -> "",
     Extensions ->
          {
               {"Documentation", Language -> "English",
                        LinkBase -> "PlotsDocumentation",
                        Resources -> {"Guides/PlotsDocumentation"}                
                }
           }
]

Now save the new file with the name PacletInfo.m in the main (outer) directory of the package, the directory Plots:

"createMathematica6AddOn_20.gif"

Close the files PlotsDocumentation.nb and PacletInfo.m
If everything is alright, then your documentation must be already accesible from the "Documentation Center" (Help menu).
Open Mathematica's "Documentation Center" in the Help menu:

"createMathematica6AddOn_21.gif"

Go to the lower-right corner of the "Documentation Center" main page (you might have to scroll-down with the mouse) and select the option Installed Add-ons:

"createMathematica6AddOn_22.gif"

The link to your documentation must be appear in the next "Documentation Center" page:

"createMathematica6AddOn_23.gif"

Click in the link and your documentation must open inside the "Documentation Center":

"createMathematica6AddOn_24.gif"

Now our package can be loaded with the Needs[ ] command and it has its documentation in the Documentation Center, in the same way as the standard Mathematica Add-ons. In the next section we will create a Palette for our package.

Contents

Create a palette for the package and place it in the Palettes menu

Finally we will create a Palette for our package. In order for the Palette to appear in "Palettes" menu in Mathematica, it is necessary to place it in a special directory. Inside the package directory (Plots) create another directory with name FrontEnd (Remember that Mathematica is case-sensitive). Inside that directory create another directory with name Palettes. We will save the Palette inside that inner directory. Remember that all this directory structure is inside the Applications subdirectory of the $BaseDirectory, as you can see in this image:

"createMathematica6AddOn_25.gif"

The following commands create a palette for this package.
Remember that Mathematica is very strict with sintaxis, for example you cannot replace the backquote ` with the quote  '
The selection place holder □ can be entered by pressing the keys [ESC]pl[ESC]
For the moment, the palette is stored in the variable mypalette:

"createMathematica6AddOn_26.gif"

"createMathematica6AddOn_27.gif"

The palette looks like this:

"createMathematica6AddOn_28.gif"

Next we save the palette in the proper directory:

"createMathematica6AddOn_29.gif"

Verify that the palette was saved in the correct place:

"createMathematica6AddOn_30.gif"

Close the palette:

"createMathematica6AddOn_31.gif"

Exit Mathematica in order to have the Palettes menu updated:

"createMathematica6AddOn_32.gif"

Enter Mathematica again. The palette will be listed in the Palettes menu. Click to open it:

"createMathematica6AddOn_33.gif"

The palette opens:

"createMathematica6AddOn_34.gif"

You can use the palette now. REMEMBER THAT THE PACKAGE MUST BE LOADED (Needs) BEFORE ANY OF ITS COMMANDS (PlotColor) IS USED, otherwise a new variable PlotColor will be created that will create conflicts (shadowing) with the PlotColor from the package

"createMathematica6AddOn_35.gif"

"createMathematica6AddOn_36.gif"

"createMathematica6AddOn_37.gif"

"createMathematica6AddOn_38.gif"

"createMathematica6AddOn_39.gif"

"createMathematica6AddOn_40.gif"

"createMathematica6AddOn_41.gif"

Now your package can be loaded with the Needs[] command, it has its documentation in the Documentation Center, and it has a Palette in the Palettes menu.

Contents

Distribute your Add-on to other Mathematica users

Now your package can be loaded with the Needs[] command, it has its documentation in the Documentation Center, and it has a Palette in the Palettes menu. In order to distribute your package, you can compress the Plots directory and send it to other users with the instructions to uncompress it in the $BaseDirectory or in the $UserBaseDirectory. See for example the instalation instrucctions of this package for doing Quantum Mechanics calculations in Dirac notation in Mathematica:  http://homepage.cem.itesm.mx/lgomez/quantum/

Contents

Author

José Luis Gómez-Muñoz

jose.luis.gomez@itesm.mx

http://homepage.cem.itesm.mx/lgomez/       

Contents


Created by Wolfram Mathematica 6.0  (19 December 2007) Valid XHTML 1.1!