Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need certain user defined functions over and over. I was wondering how can I define and where and how to save them such that each time I start a notebook, these functions are available and need not to be defined again.

share|improve this question

Best place is to make a package. But if you do not feel like it, you can put the definitions in the init.m file

using init.m

see for more information on using init.m. From the above:

"Possible locations for init.m files include the following:"

 $BaseDirectory/Kernel kernel initialization code for all users
 $UserBaseDirectory/Kernel kernel initialization code for the currently logged-in user
 $BaseDirectory/FrontEnd front end initialization code for all users
 $UserBaseDirectory/FrontEnd front end initialization code for the currently logged-in user

When using init.m you do not need to load anything, as init.m is read automatically if is is found when Mathematica starts.

Using a package

If you put the definitions in a package, say foo.m and then you can load your package, like this


or if the package is in one of the standard locations in the Mathematica $Path you can write


whenever you need to use the functions.

To make a simple package, here is a note I wrote here it has more information.

See also this question here at how to install and use a package

also WRI page on packages

Autoloading packages

For advanced packages, you can make a package that will also load automatically when Mathematica starts. These has to go to a special location though, called AutoLoad.

This link below is very useful to tell one where to put everything in Mathematica and talks more about this autoloading

share|improve this answer
Unforunately the last two hyperlinks became orphans. – Adalbert Hanßen Feb 6 at 7:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.