8

I have a bunch of user-defined functions that are frequently used in mathematica. I wonder if I can store them in separate files and mathematica will load them on start and treat them as built-in functions, so that I don't have to repeat the definitions whenever I create a new .nb file. Something similar to functions in Matlab...

Thanks!

gondolier
  • 235
  • 2
  • 5

1 Answers1

13

You can create a package in $UserBaseDirectory/Autoload. This will be loaded at Kernel initialization time.

Your package should have a Kernel/init.m file

MyPackage/Kernel/init.m

Reference documentation on Mathematica packages: http://reference.wolfram.com/mathematica/tutorial/SettingUpMathematicaPackages.html

DeclarePackage[] is a lazy loading mechanism for symbols and their definitions. The associated package is loaded only when the symbol is used:

http://reference.wolfram.com/mathematica/ref/DeclarePackage.html

Joshua Martell
  • 7,074
  • 2
  • 30
  • 37
  • Hi Joshua, we have a proposal for a [separate Mathematica site](http://area51.stackexchange.com/proposals/37304/mathematica?referrer=hWeRiD9Qz0oIDM_9uBjtlA2) under the SE network, for anything related to mma (not just programming questions like on SO). We're very close to launching (24 users remaining) and it would be great if you could commit to that proposal :) – abcd Jan 10 '12 at 05:26