Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
2  
This question might help –  Heike Mar 20 '12 at 8:40
    
In this question I use the word close, but maybe I should use the word folded instead. Is it the same? –  sjdh Mar 20 '12 at 9:05
add comment

2 Answers

up vote 4 down vote accepted

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[]
share|improve this answer
add comment

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.

share|improve this answer
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 9: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 9: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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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