Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context unique to each group at a specified level

Recent versions of Mathematica provide the option of having a unique $Context for each cell group, via:

  • Evaluation > Notebook's Default Context > Unique to Each Cell Group

This is an appealing concept, but I find it unusable, as my code spans multiple cell groups.

I would like a way to specify a unique context for cell groups of a certain level such as every Section, but not a separate context for every Subsection or Subsubsection.

A solution will need to affect new cell groups as they are created.

like image 651
Mr.Wizard Avatar asked May 05 '11 13:05

Mr.Wizard


2 Answers

You should be able to do this by modifying your notebook's stylesheet. You can use the option CellContext to set the context. The mma documentation does this to restrict example context to Cell groups.

like image 132
Sjoerd C. de Vries Avatar answered Oct 03 '22 03:10

Sjoerd C. de Vries


You can achieve this by grouping cells manually instead of relying upon the automatic grouping mechanism. In the notebook in question, use the menu item Cell / Grouping / Manual Grouping to enable manual grouping. Now, as you enter sections, subsections, etc. they will not be grouped automatically. Select the cells that you wish to be in a single group and use the menu item Cell / Grouping / Group Cells/Group Together. Now that they are grouped, you can set the CellContext to be CellGroup and they will all play well together.

like image 27
WReach Avatar answered Oct 03 '22 02:10

WReach