6
$\begingroup$

I have a notebook with grouped cells, where the input cells are hidden and only output cells open. Is it possible in an easy way to evaluate the whole notebook and preventing opening all groups, preserving the group structure?

$\endgroup$
2

2 Answers 2

2
$\begingroup$

Yes there are several ways. Firstly, note that manual grouping is broken in 12.0.0.0, but it sounds like you are using automatic grouping anyway, so that's not the problem.

Having closed input cells is not the problem either. I think the problem is that with automatic grouping, a closed section will be automatically opened when evaluated if the last cell in the closed section does not evaluate to Null. So terminate the last cell with ;, or input Null as the last cell in the section. (IMO this is a bug.)

To initiate evaluation of everything within a selection of closed groups or sections, select them then Shift+Enter. Selection is done most easily by dragging the mouse across the closed groups or sections from top to bottom, or bottom to top, starting at a position between cells where the cursor is a short horizontal bar (it can also be done by clicking cell brackets).

To evaluate the whole notebook, use the menu Evaluation -> Evaluate Notebook (alternatively, Edit -> Select All then Shift+Enter).

$\endgroup$
2
$\begingroup$

I don't remember any built-in option for this, so we may need to implement it on our own.

SetOptions[
    EvaluationNotebook[],
    CellProlog :> With[
        {
            status = (
                SelectionMove[EvaluationNotebook[], Previous, CellGroup, AutoScroll -> False];
                NotebookRead[EvaluationNotebook[]][[1,2]]
            )
        },
        SetOptions[
            EvaluationCell[],
            CellEpilog :> (
                Switch[status,
                    Closed|False,
                        FrontEndTokenExecute@"OpenCloseGroup",
                    _List,
                        (* Not implemented yet. See MSE 71897. *)Null
                ];
                SelectionMove[EvaluationNotebook[], After, CellGroup, AutoScroll -> False]; 
            )
        ];  
    ]
]

This option can be added to the StyleData for Notebook in your stylesheet.

$\endgroup$

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.