1

Say I create $UserBaseDirectory/Autoload/MyPackage/init.m containing:

BeginPackage["MyPackage`"];
Symbol1 = 1;
Begin["`MyContext`"];
Symbol2 = 2;
End[];
EndPackage[];

When I run Mathematica:

  • Symbol1 resolves to MyPackage`Symbol1 and is colored black, indicating it has a value assigned.
  • MyContext`Symbol2 does not resolve, but MyPackage`MyContext`Symbol2 does. However, there is no autocompletion and the symbol is colored blue (indicating no value assigned) even after evaluation.

Is it possible to configure my package such that MyContext`Symbol2 will resolve and have all the front-end niceties?

mfvonh
  • 8,460
  • 27
  • 42

1 Answers1

3

The standard way to expose a symbol which is defined within a private context is to define a usage string outside the private context, as in

BeginPackage["MyPackage`"];
Symbol1 = 1;
Symbol2::usage = "Symbol2 is a test symbol";
Begin["`MyContext`"];
Symbol2 = 2;
End[];
EndPackage[]; 

Actually, any mention of the symbol inside the package but outside the private context will do the job, but there is a long-standing good practice to use this requirement as an excuse to define a usage string.

Daniel W
  • 3,416
  • 18
  • 31