|
Using Add-ons
Loading An Add-on
In order to use the functions defined in an add-on, you must first load the add-on package into Mathematica. If you do not load the add-on first, you will generate multiple conflicting definitions for the same function (see Shadowing Conflicts). To load an add-on, you need to know its name and the directory in which it is located. All the standard packages that come with Mathematica are located in several subdirectories inside the AddOns/StandardPackages directory. Other add-ons should be located in either the Applications or Autoload subdirectories of $BaseDirectory or $UserBaseDirectory. See Installing New Add-Ons for more information about these installation locations.
For example, the add-on ContourPlot3D.m is located inside the Graphics directory in StandardPackages. To load ContourPlot3D.m, use the command Needs.
In[2]:=
The two backquotes in the above command should not be confused with the single quote character. The backquote character can be found on the same key as the ~ character on most keyboards.
In the above command, it was not necessary to specify the StandardPackages directory because it is on Mathematica's search path. You can get a list of directories on this search path at any time by evaluating $Path. For more information about and $Path, see The Mathematica Book: Section 1.11.2 and Section 2.12.4.
In[1]:=
Now that ContourPlot3D.m is loaded, its context appears on the search path, and we can use ContourPlot3D as we would use any built-in Mathematica function.
In[3]:=
The command Needs will load the specified add-on only if it has not already been loaded during a session. You can also use the Get command, which is represented by <<. This command will also load the ContourPlot3D.m add-on.
In[7]:=
The << command always loads the specified add-on, even if has already been loaded during a session. You should be careful not to load the same add-on twice during a session since this may cause problems using the add-on. You can check what add-ons you have loaded at any time by evaluating $Packages.
In[8]:=
Out[8]=
Shadowing Conflicts
Shadowing conflicts between function names are created when you try to use an add-on function without first loading the corresponding package. For example, you might try to fill in the area between two curves by using FilledPlot.
In[12]:=
Out[12]=
However, FilledPlot is not a built-in function, and so Mathematica does not recognize it. Instead, it creates an empty symbol within the Global` context called FilledPlot. If you now load the package FilledPlot.m, the generated error message will inform you that FilledPlot is "shadowed" by its Global` context definition, since Mathematica starts from the Global` context and moves to other contexts only if a definition does not exist in the Global`context.
In[13]:=
To fix this problem, use the command Remove in order to clear empty definitions from the Global` context.
In[14]:=
Now Mathematica finds the correct definition and FilledPlot behaves as expected.
In[23]:=

Out[23]=
Add-ons can be installed in either the Applications or Autoload subdirectories of $BaseDirectory or $UserBaseDirectory. Add-ons installed in the Autoload subdirectory are automatically loaded when the front end and kernel are started (see Autoloaded Add-ons). Add-ons installed in the Applications subdirectory can be loaded manually when needed (see Using Add-ons).
|