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'm developing a larger package which includes several subpackages. My problem is, that I can't introduce the symbols in the subpackages to the autocompletion by loading the main package, but by calling a subpackage.

Let's explain this with an example: I have a main package, called main which loads the subpackages sub1, sub2 and sub3. The directory should look like

├── Kernel
│   └── init.m
├── main.m
├── sub1.m
├── sub2.m
└── sub3.m

The package main loads all three subpackages in its BeginPackage statement, while the package sub1 loads sub2 and sub3. The respective init.m looks like:


The big problem I have is, that by calling


I can see all symbols in main, but not those in the subpackages (though, they are usable).

By calling


I can see all symbols in the subpackages without any problems but can't load main anymore, because then some definitions are redone, which leads to error messages about protected symbols. The most interesting thing is, that the $ContextPath includes the subpackages in both cases.

Is there a nice possibility to get the symbols of the subpackages into the autocompletion?

Update: By prepending the path of a subpackage to the $ContextPath, I can load the corresponding symbols of that package into the autocompletion.

$ContextPath = Prepend[$ContextPath, "main`sub1`"]

Unfortunately, this is not very nice and yields duplicates in the $ContextPath.

Is there a better, automatic way to achieve this?

share|improve this question

I think you have deal with Mathematica application.

I know 2 way for solv this problem

1) Add path to your application in variable $Path. And then load with Get


This code try to find init.m in your application and evaluate it.

2) Save your application in directory $UserBaseDirectory <> "\\Autoload" and it will load with mathematica start (withe the way described in previous way).

share|improve this answer

Just to give additional information, what I found, at least in Mathematica version 9, is that one must load the subpackages after the main package in order to have autocompletion for the subpackages symbols. When we do this the subpackages appear before the main package in the $ContextPath, so when you have a init.m like this:


you have $ContextPath = {main`sub3`, main`sub2`, main`sub1`, main`main`, ...}, and voilà, we have autocompletion.

I don't understand why Mathematica "shadows" the subpackage symbols when they appear after the main package in the $ContextPath, but this is the solution I found.

share|improve this answer

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.