Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4050068
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:01:27+00:00 2026-05-20T14:01:27+00:00

As I never found (or perhaps I never search for it enough) a good

  • 0

As I never found (or perhaps I never search for it enough) a good article about how to manage the init.m files, I ended up developing my own “standard”, but I wonder how bad I did it.

For example, my usual init.m is stored in C:\Documents and Settings\All Users\Application Data\Mathematica\Kernel\init.m (Windows) and I edit it using a text editor.

As I don’t want the definitions to go into the Global context, the content is something like:

(** User Mathematica initialization file **)
Begin["MyInitContext`"];

Cl:=Clear["Global`*"];
(* Other definitions in this Context *)

End[]; (* End Context *)
$ContextPath = Prepend[$ContextPath,"MyInitContext`"];

I don’t load packages from the init.m, because I want strict control over what I load, so I only define here shortcuts to utility functions I use on a daily basis and some options.

So: Any references to good practices? Better ways to achieve this kind of behavior? Any caveats?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:01:28+00:00Added an answer on May 20, 2026 at 2:01 pm

    Firstly, I would strongly recommend against putting anything significant init.m, since this invariably results in old stuff being broken when you come back to it after a few years. Much better to put your customizations on the path so you can quickly load it at the head of each notebook: That way the context is explicitly stated and you can easily change versions without breaking old stuff.

    My current setup is to start with Needs["Janus`"] where the Janus directory has a custom init.m file that loads every file in the directory into the context. This means I can add utility functions in each their own file like this one (clear_cache.m):

    ClearCache::usage="ClearCache[f] unsets all numeric-only downvalues of f, \
      see http://stackoverflow.com/questions/5086749"     
    
    Begin["`Private`"];
    ClearCache[f_Symbol] := 
      DownValues[f] = DeleteCases[DownValues[f], _?(FreeQ[First[#], Pattern] &)]
    End[]
    

    Here is the file Janus/init.m. Note that it prints out the name of the loaded extensions, all in the spirit of keeping the context explicit without too much hassle.

    Module[{packageName,packageFileName,fileNames},
      (* $Input is set to Foo.m when evaluating Foo/init.m *)
      If[$Input=="", Print["init.m cannot run interactively"];Abort[]];
      packageName=StringDrop[$Input,-2];
      packageFileName=FindFile[packageName<>"`"];
      If[packageFileName==$Failed, Print["Unable to find package "<>packageName];Abort[]];
      fileNames=Select[
        FileNames["*.m",{DirectoryName@packageFileName},1],
        FileBaseName[#]=!="init"&];
      Print["Loading extensions from "<>DirectoryName@packageFileName<>" to context "<>packageName<>"`:"];
      BeginPackage[packageName<>"`"];
      Do[Print["Loading "<>fn]; Get@fn, {fn,fileNames}];
      EndPackage[]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After lots of attempts and search I have never found a satisfactory way to
A problem I ran into a while back I never found a good solution
I've always been intrigued by Map Routing, but I've never found any good introductory
I have never really found the design view in Visual Studio useful when developing
This is something I've pseudo-solved many times and have never quite found a solution
I always have found the open source space interesting but have never actually participated
I've never used Smalltalk, but I've read a lot about it and it has
One thing I have continually found very confusing about using an object database like
Did about 30 minutes worth of searching, found lots of relevant info, but none
I found the web downloader but they never seem to work for me, how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.