Bug introduced in 12.3 or earlier and persisting through 13.1.0

I have a long notebook with Section, Subsection, Text, Code etc. Now when I evaluate the notebook, it expands all the cells. This causes inconvenience sometimes when you have to go to a particular section, subsection, or code since one now has to scroll a lot or close the section, or subsection manually over the course.

Is there any way I can evaluate the notebook using the Evaluation ► Evaluate Notebook menu item, but keeping the closed cell groups not expanded?

For example, I want a closed section to remain closed after the evaluation.

I tried unchecking the Cell/Cell Properties/ Open, but no luck.

EDIT: This is a minimal example to show the problem with one Section, one Subsection, one Text, and one Code cell.

enter image description here

  • 2
    $\begingroup$ Your update clarifies the behavior, but it makes your question confusing. If the notebook has a trailing executable cell (e.g. Input), and that last executable cell is in a closed group, the group will indeed open. But your frustration seemed to be based on intermediate groups opening. You mentioned the inconvenience of having to scroll further. Only the final group opens, and then only if it's terminated with an executable cell. You can easily suppress that by adding a non-executable cell at the end. So, it doesn't seem like this accurately describes the behavior you're frustrated with. $\endgroup$
    – lericr
    Jul 28, 2022 at 20:11
  • 1
    $\begingroup$ I just don't know. I do see the "last group that has terminating input cell opens" behavior, but I don't see intermediate groups open. I really don't know what governs this. look throught the options inspector maybe? or maybe it's a cell property that you can set with styles? I can imaging that it's annoying, but I'm just not having the same experience, so have never explored this. $\endgroup$
    – lericr
    Jul 28, 2022 at 23:24
  • 1
    $\begingroup$ I observe on Windows 10 x64 very similar behavior to what @lericr observes on Mac: only the last cell group opens, and only if it has a trailing cell having Evaluatable -> True and it's previous output. It is strange, but if the last cell group ends with an evaluatable cell without output, it doesn't open! This last observation (as well as different behavior across platforms) finally ensures me that the described behavior is a regression bug in the recent Mathematica versions. Added the "BUG" header and the tag. Please report it to the support. $\endgroup$ Jul 29, 2022 at 5:10
  • 1
    $\begingroup$ In my case, all the cells which have output are expanded, it does not matter if they are intermediate cells or the last. Only those cells which do not have output remain closed. I don't see the above behavior when I try to replicate it with copies of dummy test like the gif above with a lot of Title, Section, Code but on my real example (which unfortunately I don't have any means to show it here) it happens. I will file a bug report but it will be very difficult to explain the situation there. $\endgroup$
    – BabaYaga
    Jul 29, 2022 at 8:29
  • 1
    $\begingroup$ Obviously the behavior is both inconsistent and platform-dependent. I think providing a link to this discussion will help. $\endgroup$ Jul 29, 2022 at 9:09

1 Answer 1


One way to get a Notebook evaluated without side-effects like opening cell groups is do not insert the results of the evaluation into this Notebook:

NotebookEvaluate[nb, InsertResults -> False];

In this case all the cells in the Notebook nb will be evaluated without changing the nb in any way. You can apply this method even to the EvaluationNotebook[] itself, but in this case a little trick is necessary to prevent infinite recursion:

SetOptions[EvaluationCell[], Evaluatable -> False];
NotebookEvaluate[EvaluationNotebook[], InsertResults -> False];
SetOptions[EvaluationCell[], Evaluatable -> True];

Another option I just discovered is to put at the end of the cell group a cell with Evaluatable -> False (for example, it may be a usual "Text" cell or a Horizontal Line Object). In this case after using the menu item Evaluation ► Evaluate Notebook the results of evaluation will be inserted without opening the cell group where they will appear. I found this with Mathematica version 13.1 on Windows 10 x64.

It is also interesting that with Mathematica version 8.0.4 the cell groups won't be opened even without a trailing cell with Evaluatable -> False. Hence this behavior is new in the recent versions, and may be unintentional (a consequence of a bug). I recommend reporting this to the official support with a reference to this answer.

Further discussion

On Windows 10 x64 I observe something very similar to what lericr observes on Mac: if a Notebook contains several closed cell groups containing evaluatable cells, only the last cell group opens after Evaluation ► Evaluate Notebook, but only if this last cell group ends with an evaluatable cell and it's sole output. It is strange, but if the last cell group ends with an evaluatable cell without output or with two or more output cells, it doesn't open! This last observation finally ensures me that the described behavior is a regression bug in the recent Mathematica versions. Please report it to the support.

From the observation that the last cell group opens only if it has a trailing evaluatable cell with an output cell, comes a workaround: before evaluating the Notebook, just delete all the output using the Cell ► Delete All Output menu item, and only then execute Evaluation ► Evaluate Notebook. This method can easily be automatized:

SetOptions[EvaluationCell[], Evaluatable -> False];
SetOptions[EvaluationCell[], Evaluatable -> True];

A nice feature of the Cell ► Delete All Output menu item is that it deletes the cells having GeneratedCell -> True only immediately following a cell with Evaluatable -> True, and doesn't delete standalone cells with GeneratedCell -> True (which you possibly have manually created by copying). This method won't have an impact on the performance, because in any case after evaluation of a cell it's existing output is removed before inserting the newly generated output (even if the new ouput is Null, i.e. no output cell will be created).

However, if a cell prints something using CellPrint or NotebookWrite (but not Print!), the target cell group will be expanded in any case. This aspect of behavior is the same as in version 8.0.4.


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.