6
$\begingroup$

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.

$\endgroup$
2
  • 2
    $\begingroup$ This question might help $\endgroup$
    – Heike
    Mar 20, 2012 at 8:40
  • $\begingroup$ In this question I use the word close, but maybe I should use the word folded instead. Is it the same? $\endgroup$
    – sjdh
    Mar 20, 2012 at 9:05

2 Answers 2

5
$\begingroup$

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[]
$\endgroup$
2
$\begingroup$

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.

$\endgroup$
3
  • 1
    $\begingroup$ @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. $\endgroup$
    – sjdh
    Mar 20, 2012 at 9:03
  • $\begingroup$ 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 $\endgroup$ Mar 21, 2012 at 9:25
  • 1
    $\begingroup$ @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 $\endgroup$
    – sjdh
    Mar 21, 2012 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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