I want to have my entire notebook be a conditional while statement. However, I don't want to merge all of my cells together, as it is a long and detailed process. Is there a way to create another cell that encompasses all of the smaller cells in my notebook?

  • $\begingroup$ What do you mean by "I want to have my entire notebook be a conditional while statement?" Have you looked at Cell Groups? $\endgroup$
    – Mr.Wizard
    Jun 11, 2014 at 13:45
  • $\begingroup$ Just guesswork, but this could be useful: Creating Mathematica packages. Otherwise, your question is unclear. $\endgroup$
    – Yves Klett
    Jun 11, 2014 at 13:50
  • $\begingroup$ I want to be able to combine all of my original cells into a larger cell without losing the smaller subcells. I don't know how topics in Cell groups would help if I am trying to span across multiple cells to create another cell. @Mr.Wizard $\endgroup$
    – Kaisey
    Jun 11, 2014 at 14:08
  • $\begingroup$ Is is possible to simple rerun the notebook if, at the end, a certain condition is not met? $\endgroup$
    – Kaisey
    Jun 11, 2014 at 14:23

2 Answers 2


I guess you are looking for something like this:

 If[condition, NotebookEvaluate[EvaluationNotebook[]]]

I'd suggest its somewhat cleaner to create a second 'control' notebook with some code similar to this:

 While[condition , NotebookEvaluate[First@Notebooks["Untitled-4"]]
  • $\begingroup$ your code seems to work, but I cannot figure out how to get the output of my cells to show. $\endgroup$
    – Kaisey
    Jun 11, 2014 at 18:54
  • $\begingroup$ I don't follow that - the output appears in the notebook same as if you did select-all;shift-enter. $\endgroup$
    – george2079
    Jun 12, 2014 at 15:26

Grouping power is controlled by the Option CellGroupingRules, frequently defined in the style sheet system. The outermost Cell style by default is Title and has CellGroupingRules->{"TitleGrouping", 0}. Smaller values group larger values, and 0 is the smallest that is normally present. If you create a new Cell with negative value in this place it will group all below it.

For example if I create a new Cell (as entered in the Show Expression view):

Cell["Entire Notebook", "Title", CellGroupingRules->{"TitleGrouping", -10}]

It will group everything under it, e.g.:

enter image description here


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.