Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there any way to have the functions from a mathematica file be loaded on startup?

For example, in this excellent answer, Jens helps me out and gives me some functions for creating legends for plots. Instead of loading a file with those functions in it every time I load mathematica, can I instead put all the functions in a file and have them load every time I load mathematica?

share|improve this question
3  
Entering two words from your question (load startup) in the documentation search bar yields tutorial/ConfigurationFiles as first hit. -1 for not first searching documentation. –  Sjoerd C. de Vries Jun 6 '12 at 20:49
    
Related: stackoverflow.com/q/5293105/618728 –  Mr.Wizard Jun 7 '12 at 0:26

2 Answers 2

up vote 15 down vote accepted

There are several configuration files that you can use to load functionality at startup. They have the form

($BaseDirectory | $UserBaseDirectory)/(Kernel | FrontEnd)/init.m

where

$BaseDirectory 

is for every user on the system and

$UserBaseDirectory

is for you along and Kernel or FrontEnd specifies what you are configuring. In fact, a lot of the settings under the Preferences menu automatically write to $UserBaseDirectory/FrontEnd/init.m.

In your case, you are looking to add to $UserBaseDirctory/Kernel/init.m.

share|improve this answer
6  
FileNameJoin[{$UserBaseDirectory,"FrontEnd","init.m"}] for OS independency. –  Sjoerd C. de Vries Jun 6 '12 at 20:47

With $UserBaseDirectory/Kernel/init.m the most obvious place to put code which should be autoloaded has been mentioned.

But I think it might be worth mentioning that there is also the Autoload directory within $UserBaseDirectory where you can put any package file or package directory and those will automatically be loaded at startup. For the purpose mentioned I think that might be an even better place (after having the code set up as a proper package of course...).

I have not checked when the Autoload packages are loaded, but I know that init.m is loaded at a quite early stage, where I think some functionality that needs Java or the PacletManager might not yet be available. So that might also make a difference, depending on what the code actually does...

share|improve this answer

Your Answer

 
discard

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.