One way to enhance a package is to add to Maple's context-sensitive menus some new menu entries which utilize that package's features.
In Maple's Standard GUI, context-sensitive menus (a.k.a. context-menus) appear when the mouse is right-clicked over (input or output) 2D Math expressions.
For a package implemented as a module, new and relevant context-menu entries can be created inside the module's ModuleLoad export. That will cause the new menu entries to be created (automatically) upon the first invocation or use of the package.
Moreover, such new context-menu entries can be configured so as to only appear under specific circumstances -- such as when the package is loaded (using with).
The following is an example. Note that running this code will create a file named myp.mla in one's home directory/folder.
restart:
mypackage := module()
option package;
export _pexports, f, ModuleLoad;
local pCM;
ModuleLoad := proc()
pCM := ContextMenu:-CurrentContext:-Copy():
pCM:-Queries:-Add(
"Is mypackage Loaded",
proc()
member( :-mypackage, packages() );
end proc);
pCM:-Entries:-Add("f",
":-mypackage:-f(%EXPR)",
'Matrix(square)',
'operator'=Typesetting:-mover(Typesetting:-mo("→"),
Typesetting:-mi("f")),
'active'="Is mypackage Loaded",
'category'="Category 1",
'helpstring'="apply f to Matrix",
'submenu'=["mypackage"]
);
ContextMenu:-Install(pCM);
end proc;
f := proc(M)
LinearAlgebra:-Determinant(M);
end proc;
_pexports := () -> [ op( { exports( mypackage ) } minus
{ ':-_pexports', ':-ModuleLoad' } ) ];
end module:
FileTools:-Remove(cat(kernelopts(homedir),"/myp.mla")):
LibraryTools:-Create(cat(kernelopts(homedir),"/myp.mla")):
libname:=kernelopts(homedir),libname:
savelib('mypackage');
restart:
libname:=kernelopts(homedir),libname:
# Without the package loaded, its menus aren't present.
# Right-click on the Matrix output below.
A := Matrix([[1,2],[3,9]]);
# With the package loaded, its menus appear.
# Right-click on the Matrix output below.
with(mypackage);
A;
Here are a few of the options to the Entries:-Add routine (an export of a context-menu module, see the ?ContextMenu[CurrentContext][Entries][Add] help-page):
acer
2 hours 29 min ago
2 hours 36 min ago
8 hours 7 min ago
15 hours 27 min ago
15 hours 50 min ago
16 hours 49 sec ago
18 hours 2 min ago
18 hours 16 min ago
18 hours 23 min ago
19 hours 5 min ago