18
$\begingroup$

I'm working on a large notebook and I want to exclude some sections and subsections from being evaluated when I evaluate the whole notebook.

Is there a way to exclude specific sections or subsections from the notebook evaluation while maintaining their original format? Or even better, format them e.g. by adding a gray background?

$\endgroup$
3
  • 1
    $\begingroup$ Rather than specify which sections to not evaluate, you can specify which you do want to evaluate, by setting them to be initialization cells, and evaluating only initialization cells. $\endgroup$
    – jVincent
    Commented Feb 15, 2013 at 11:51
  • $\begingroup$ Or, you can select those cells that you don't need to evaluate and comment them (Edit menu -> Un/Comment Selection). $\endgroup$
    – VLC
    Commented Feb 15, 2013 at 12:08
  • $\begingroup$ See mathematica.stackexchange.com/questions/14466/… for another approach. $\endgroup$
    – cormullion
    Commented Feb 15, 2013 at 12:24

1 Answer 1

20
$\begingroup$

This solution only works in version 9. Create a private stylesheet, and add style cells for any Section, etc., styles that you want to create using the following pattern:

Cell[StyleData["NonEvaluatingSection", StyleDefinitions -> StyleData["Section"]],
 PrivateCellOptions->{"CellGroupBaseStyle"->{Evaluatable -> False,
   Background->RGBColor[0.8, 0.8, 0.8]}},
 MenuSortingValue->10000]

"CellGroupBaseStyle" is new to version 9, and it allows you to layer in options to all cells which are grouped by the given style. So, in this case, we have a style "NonEvaluatingSection", which has all of the properties of the style "Section", except that it adds a background and Evaluatable->False to itself and all of the cells grouped by it. The option is not documented, but that's just an oversight. It will be in a future release.

If, for example, you've added the above to the notebook's private stylesheet, then you can simply set the style of the head cell of any sections you don't want to evaluate to "NonEvaluatingSection" style (which you'll now see in the Format->Style menu).

$\endgroup$

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.