I'm trying to separate my document into cell groups, each with their own context (much like the style of code isolation described by the answer here: Localizing variables within a Manipulate), but the I can't get the grouped cells to share a context, even though Notebook's Default Context is set as "Unique to each cell group."

I have a simple example. The linked notebook appears as a single cell group (when I look at the grouping bars along the right side of the window), but multiple calls of Print[$Context] yield different results.

It seems like, once a cell has been created, it's context doesn't change even if I adjust the grouping. What is going on in the simple example I posted, and is there a way to fix these weird context differences/prevent them from happening?


  • 1
    $\begingroup$ With 8.0.4 on Mac 10.6.8 I find cell contexts changing whenever the grouping is changed. What version and platform are you using? $\endgroup$ Commented Feb 17, 2013 at 21:52
  • $\begingroup$ Oh, huh, does the above document print all the same or all different $Context numbers for you? I'm using 9.0.0 on Ubuntu 12.10. $\endgroup$
    – Sam Bader
    Commented Feb 17, 2013 at 23:43

1 Answer 1


I should mention that I eventually resolved this confusion. Fultz's answer (referenced above) said

Separate the examples into cell groups. You can use, e.g., Section or Subsection cells to do this

I was thinking of cell groups merely as any cells joined by the brackets on the right-side of the screen, and I was manually adjusting the grouping. This did not work. Evidently, using Section or Subsection cells is the appropriate way to have Mathematica treat cell groups properly for variable isolation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.