|
Autoloading Packages
Explicit loading of packages is useful if you are trying to minimize the amount of memory used by your Mathematica session or if you are in an early stage of package development. However, most users find that they use a particular set of packages often, and they want those packages to load automatically.
Initialization Packages

Initializing all packages in a directory.
If you frequently use many functions from different packages in the same standard package directory, you will find it convenient to load the initialization package from that directory. After you load the initialization package you can use any of the functions contained in packages included in the directory. You will not need to load each package separately.
For example, <<Graphics` loads the initialization package Graphics`Kernel`init` and makes all the functions provided in the Graphics packages available in your current session. Using one of these functions will cause the appropriate package to be loaded if it has not been loaded already. An initialization package really consists of nothing more than a sequence of DeclarePackage commands.
This loads the Graphics`Kernel`init` package. All the functions contained in Graphics packages are now available for use.
In[1]:= <<Graphics`
Since the Graphics`Graphics` package defining BarChart has not yet been loaded, using BarChart will cause the package to load.
In[2]:= BarChart[{1.2, 3.4, 2.2, 1.8}]

Out[2]= 
Autoload Directory
The Mathematica distribution typically includes the standard add-on packages described in this book, placed in the AddOns/StandardPackages/ subdirectory of your main Mathematica directory. Additional add-ons, created by users and developers or purchased separately from Wolfram Research, are generally placed in subdirectories of the $AddOnsDirectory or the $UserAddOnsDirectory, depending on whether the packages are to be made available to all users of this copy of Mathematica, or only a single user. These symbols evaluate to the actual directory on your system where add-ons should be placed. See Appendix A.8.7 of the Mathematica book for more information on these directories. Mathematica application packages, such as Electrical Engineering, are usually installed in an Applications subdirectory. An Autoload subdirectory provides another way to autoload packages.

Directories for Mathematica packages.
If you would like Mathematica to automatically load the initialization file for a directory of packages whenever you start the kernel, then you should copy the initialization file out of the location in the main Mathematica layout into the appropriate Autoload subdirectory of an add-ons directory. For example, you might copy $TopDirectory/AddOns/StandardPackages/Graphics/Kernel/init.m into $AddOnsDirectory/Autoload/Graphics/Kernel/init.m so that all graphics packages will load as needed. If you have the Electrical Engineering application, you might copy $AddOnsDirectory/Applications/EE/Kernel/init.m into $UserAddOnsDirectory/Autoload/EE/Kernel/init.m so that the Electrical Engineering application will load as needed for your own sessions. Effective use of the Autoload directory allows you to create a version of Mathematica tailored to your needs.
|