1
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ I believe this question is answered here: (29324) (I am sorry no one directed you to this Q&A sooner.) $\endgroup$ Commented Sep 15, 2014 at 14:18

1 Answer 1

3
+50
$\begingroup$

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.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.