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.

I can't get any function defined in $UserBaseDirectory/Kernel/init.m to work. For example:

SinDeg[d_] := Sin[d * Degree]; (* Only line in init.m *)

Output:

SinDeg[90]
(* => SinDeg[90] *)

However when copying the code and executing it inside a Mathematica notebook, it works fine:

SinDeg[d_] := Sin[d * Degree];
SinDeg[90]
(* => 1 *)

The Mathematica front-end can definitely see the function definitions as it displays SinDeg as an autocompletion suggestion, when typing SinD.

I'm using Mathematica 9 Home Edition on OS X.

share|improve this question
    
To eliminate the obvious: you have restarted Mathematica after adding this line to init.m? –  Sjoerd C. de Vries Mar 11 '13 at 23:50
    
@SjoerdC.deVries yes. –  Tyilo Mar 11 '13 at 23:51
    
What do you get when you type ?SinDeg directly after Mathematica starts up? –  Sjoerd C. de Vries Mar 12 '13 at 0:42
    
@SjoerdC.deVries I get this error: Information::notfound: Symbol SinDeg not found. >> –  Tyilo Mar 12 '13 at 0:44
    
Could you check whether you really have an underscore in your definition in the init.m file? –  Sjoerd C. de Vries Mar 12 '13 at 0:44
show 17 more comments

1 Answer 1

up vote 3 down vote accepted

This has to do with the Notebook's default context setting in the evaluation menu. If it isn't set to Global`, the definitions made in init.m are not seen.

As rm-rf says, a good way to put custom definitions in the init.m would be to use Begin and End to create an Init` context and append that context to the context path so that the definitions are available regardless of the notebook's context. (better still, use packages)

share|improve this answer
add comment

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.