# Automatically load packages at startup

I'm a physics student and I try to simplify my day with Mathematica. Every time I use Mathematica I need Div[], Grad[], Curl[], etc., so I use Needs["VectorAnalysis"].

My question is: Is there any way to tell Mathematica that the package VectorAnalysis should always be loaded? It would simplify my day enormously.

By the way, I tried

DeclarePackage["VectorAnalysis", {"Div", "Grad", "Curl"}]

When you first use Grad, Mathematica automatically loads the package that defines it.

Unfortunately, nothing happens. The functions are still unknown, until I use Needs["VectorAnalysis"]

What am I doing wrong, and how do I fix my problem?

-
Look up init.m in the docs. –  Ｊ. Ｍ. Jul 12 '12 at 0:07

To load the VectorAnalysis package on each startup, you can write the init file using Export. The snippet below will append a Needs["VectorAnalysis"] to the kernel init.m file:
initFileName = FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]; (* Make a back-up *) CopyFile[initFileName, initFileName <> "_" <> StringReplace[ToString@Round[DateList[]], " " -> ""] <> ".bak"]; exprs = Import[initFileName, {"Package", "HeldExpressions"}]; Export[initFileName, Append[exprs, HoldComplete[Needs["VectorAnalysis"]]], {"Package", "HeldExpressions"} ] - Warning. This routine hosed my init.m file, completely emptying it. (Running Mma 7 on Win 7.) – Chris Degnen Jul 12 '12 at 9:39 I´d also opine that modifying important init files by hand would be the safer alternative than scripting (even with backup) in most cases – Yves Klett Jul 12 '12 at 15:08 THANKS MAN!!!! U MADE MY DAY!! Thats exacly what i want....nice I'm new in this board, but actually now i think one of the most efficient boards...thanks again...maybe u'll hear about me with another question, but i hope next time, i can help :) – Max Hacki Jul 12 '12 at 21:39 add comment On Mathematica 7 (at least) DeclarePackage doesn't work first time on this Curl example: DeclarePackage["VectorAnalysis", {"Div", "Grad", "Curl"}] v := {3 Xx^2 + 2 Yy + (a - 3 b) Zz, (b - 7 a) Xx - 5 Yy - Zz, 2 Xx + c a Yy + 7 Zz} Curl[v] {0, 0, 0} But strangely when v is defined again and run it works: v := {3 Xx^2 + 2 Yy + (a - 3 b) Zz, (b - 7 a) Xx - 5 Yy - Zz, 2 Xx + c a Yy + 7 Zz} Curl[v] {1 + a c, -2 + a - 3 b, -2 - 7 a + b} On the other hand Needs works first time: Quit Needs["VectorAnalysis"] v := {3 Xx^2 + 2 Yy + (a - 3 b) Zz, (b - 7 a) Xx - 5 Yy - Zz, 2 Xx + c a Yy + 7 Zz} Curl[v] {1 + a c, -2 + a - 3 b, -2 - 7 a + b} You could manually add Needs["VectorAnalysis"] to the init file referred to by Malte, found at FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}].