Loading packages in a clean session in tutorial and symbol pages with Mathematica Workbench 2.0
Asked Answered
G

1

5

I am developing documentation for a package with Workbench. So far I have used

Quit[]
Needs["mypackage`"]

at the beginning of each Tutorial. This is because I want a clean global environment and package loading at the same time.

I ran some builds and everything worked as expected, but I wonder: is there a better way to have a clean global context and the package context load "automatically" each time a launch a tutorial for my package with MMA?

In other words: going from one tutorial to the next, or from a tutorial back to a regular MMA notebook, is it possible that all symbols defined in the tutorial examples be "forgotten"? In the standard MMA tutorial pages, this is what seems to happen.

I suppose this could be done this a local/notebook context.

But how would this work in practice?

Thank you for your help

Gonsalve answered 23/10, 2011 at 14:36 Comment(1)
@Brett or others: I have another old question on Workbench, which I just edited. But it does not seem to get the spotlight anymore. So if you could please have a look at it, here is the link. #7738557 Thank youGonsalve
K
9

For each tutorial, choose the menu item Evaluation > Notebook's Default Context > Unique to this Notebook. This will make each notebook have a new, unique, context. So then you don't need the Quit[] (which seems like a pretty drastic method.) There are probably a few ways you could make sure the Needs cell is run, but making it an initialization cell is probably the easiest.

Kine answered 23/10, 2011 at 15:6 Comment(3)
something very strange happens: I have selected "Unique to this Notebook" context for my tutorials, made a build and then previewed the project. Well...it does not work! If i type a=10 in a tutorial cell, and then ?a, I get Global`a. Yet the correct "Unique to this Notebook" context is ticked in the Evaluation menu.Gonsalve
I was too quick to comment. Unfortunately things are not so clear. Something very strange happens: I have selected "Unique to this Notebook" context for my tutorials, made a build and then previewed the project. Well...it does not work! If i type a=10 in a tutorial cell, and then ?a, I get Global`a. Yet the correct "Unique to this Notebook" context is ticked in the Evaluation menu. Continue on the next commentGonsalve
Continued from above. On the other end in my guide page - which I think I did not change at all and which shows a Global` default context in the Evaluation menu - the same test works: I type a=10 ?a and I get Cell$$xyz'a so the context is localized to a cell. Also: if you check the tutorial LightweightGridClient/tutorial/Introduction you will see that the above test works (you get Notebook$$xyz'a), yet the Evaluation menu shows a Global' default context. So can anybody explain this?Gonsalve

© 2022 - 2024 — McMap. All rights reserved.