6

Styles can be used to give your calculation a book-like structure; with chapters, sections and paragraphs. Closing those subgroups of cells you don't want to see is then very powerful to create visual order. I use this to keep oversight of my calculation. The cells containing the actual calculations I close, and only the titles and heads are visible.

This works well until I evaluate cells. Whenever a result or message is printed, the cells open automatically, and the notebook becomes a mess again. My question is: how can I prevent these cells from opening ?

I have some ideas, but I would like to hear if you have any (better) alternatives. This I what can think of:

  • Add a semicolon after each line.
  • Use Block[{Print}, Expression} to suppress Print statements

The side effect of these methods is that no results or messages are printed at all. I would like them to be printed though. At the same time I want to decide my self when to open a cell or not.

sjdh
  • 7,757
  • 5
  • 37
  • 47

2 Answers2

5

Adapting this answer, please try this:

autoFoldOutput[] := (If[$FrontEnd =!= $Failed, 
   SelectionMove[EvaluationNotebook[], All, EvaluationCell];
   FrontEndTokenExecute["SelectionCloseUnselectedCells"]])

And then in a new cell:

2 + 2
autoFoldOutput[]
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
2

One way you may follow is to declare the cell as "Closed". To do this go to Menu/Cell/Cell Properties and uncheck "Open". You may also declare this same cell as the Initialization Cell (again in the Menu/Cell/Cell Properties). In this case you will be able to evaluate closed Initialization Cells without reopening them. This may be done either by going to Menu/Evaluation/Evaluate Initialization Cells or by evaluating any code in the notebook containing the cells in question.

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96
  • 1
    @Boulbitch I tried your suggestions. I created a section and put this statement in it: For[i = 0, i < 10, i++, Print[i]]. Then I changed the cell properties, and I folded all cells. Evaluation unfolds all cells again, but I want keep them folded. – sjdh Mar 20 '12 at 09:03
  • I tried this in the following steps: (1) added a cell with your operator: For[i = 0, i < 10, i++, Print[i]] and marked it (2) in Menu/Cell/CellProperties checked "Initialization Cell" (3) in Menu/Cell/CellProperties unchecked "Open". The cell collapsed. In Menu/Evaluation I clicked "Evaluate Initialization Cells". The operator has been executed, but the cell in question did not open. So I cannot see the problem. Try to follow my steps. Alexei – Alexei Boulbitch Mar 21 '12 at 09:25
  • 1
    @Boulbitch I did exactly what you said. In step (4) In Menu/Evaluation I clicked "Evaluate Initialization Cells", an output cell is created that has 10 cells with the number 0...9. These cells are open. I use Mathematica 7 – sjdh Mar 21 '12 at 13:49