I have tagged certain Input cells I want to be closed during a presentation. I close them as follows:

Do[CurrentValue[cell, CellOpen] = False,
 {cell, Cells[CellTags -> {"noclass"}]}

The problem: the associated Output cells also closed, even though they are not tagged. (I assume the CellOpen setting is being inherited?) How can I keep these Output cells open (or reopen them without opening the tagged Input cells)?


The comments say it is the tag that is inherited, not CellOpen. One answer suggests on this basis to try

Do[CurrentValue[cell, CellOpen] = False, {cell, 
  Cells[CellStyle -> {"Input"}, CellTags -> {"noclass"}]}]

I had already tried this unsuccessfully. I had even followed up with

Do[CurrentValue[cell, CellOpen] = True, {cell, 
  Cells[CellStyle -> {"Output"}, CellTags -> {"noclass"}]}]

However, in fact if I run these in isolation they sometimes work. (That sometimes is a warning; I have not been able to pin down.) Here is what appears to have created a problem for me.


If I execute these front-end tokens, tagged input cells seem to be grouped with their output. There then appears to be no way to open the output without opening the input ... that is, I have not found one.

Edit #2:

Here is how I currently understand my situation, after the helpful comments below.

When I select everything and close all groups, this naturally closes the input-output groups. When I subsequently execute the notebook, it leaves all groups closed except the input-output groups, which change to an open state. (Perhaps they are even considered to be "new" cell groups, so they get a default state of open?)

In contrast, suppose I close all groups but do not subsequently evaluate the input cells, so the input-output groups remain in a closed state. The display for a closed input-output group is the input cell. (Right?) So when the input cell (of a closed input-output group) is in a closed state, nothing displays, even if the output is in an open state. I cannot change the display state of an input-output group simply by changing the display state of its cells.

If this is all correct, we arrive to my question: how can I change the display state (to open) of all input-output groups in a notebook, without opening any other groups and without changing the CellOpen state of the input cells? I would like to do something like


but that GroupOpen property does not appear to exist. (Or am I just not finding it under another name?) I would also be happy to select all input-output groups and toggle the "OpenCloseGroup", but I do not see how to make that selection.

Edit #3:

While not exactly what I was searching for, the following gets me where I was trying to go:

(* start with initial state of all groups open *)
(* use tag to choose input cells to keep invisible *)
testInputs = Cells[CellStyle -> {"Input"}, 
  CellTags -> {"test"}];  (* input cells to keep invisible *)
Do[CurrentValue[cell, CellOpen] = False, {cell, 
  testInputs}] ;  (* close them (i.e., invisible *)
(* prepare notebook for presentation by closing sections *)
cells2close = Cells[CellStyle -> {"Section", "Subsection", "Subsubsection"}]
SelectionMove[#, All, Cell]; FrontEndTokenExecute["OpenCloseGroup"]; & /@ cells2close;

The only thing missing is that I specify which groups to close instead of closing all except the input-output groups.

  • 1
    $\begingroup$ It's not CellOpen what is inherited but CellTags. $\endgroup$
    – Kuba
    Aug 29, 2015 at 9:05
  • $\begingroup$ Please provide an example Notebook with the problem for testing. $\endgroup$ Aug 29, 2015 at 16:57
  • $\begingroup$ @AlexeyPopkov Not sure how best to do that. Does this work? $\endgroup$
    – Alan
    Aug 29, 2015 at 19:11
  • $\begingroup$ @Alan I have checked your Notebook with Mathematica 10.2 on Win7 x64 and everything works as expected. The Output cell which is grouped with closed Input cell can be seen by double-clicking the right frame of the cell group which appears as arrow. Which version and on what OS do you use? $\endgroup$ Aug 30, 2015 at 13:47
  • $\begingroup$ @AlexeyPopkov You say everything works as "expected". 1. Did everything work as I described in the Notebook. (Because what I carefully described cannot I think be considered "expected".) 2. How can I programmatically open those output cells, so that Section 1 behaves just like it does when I evaluate the whole notebook? (Btw, I am on the same Mma version and OS.) Thanks! $\endgroup$
    – Alan
    Aug 30, 2015 at 14:20

1 Answer 1


You can explicitly specify that only "Input" Cells should be closed:

Do[CurrentValue[cell, CellOpen] = False,
 {cell, Cells[CellStyle -> {"Input"}, CellTags -> {"noclass"}]}

As Kuba notes in the comment, it is CellTags what is inherited by generated output Cell. This issue recently raised in this question. If the inheritance is not desirable you can use CellID instead of CellTags.


From the discussion in the comments I see your confusion: you misinterpret the meaning of the option CellOpen. This option is NOT related to opening or closing of Cell groups, it just hides the content of a Cell when is set to False for that Cell.

In your example Notebook you evaluate FrontEndTokenExecute["SelectionCloseAllGroups"], this piece of code collapses all the Cell groups within the selection but does not close the Cells in the meaning of the option CellOpen. Similarly, you cannot open a Cell group by setting the option CellOpen for a Cell inside of that group! This is the reason why the code Do[CurrentValue[cell, CellOpen] = True, {cell, Cells[]}] does not open any group. For opening a group you have to explicitly open it. One way to do the latter is to select the group and then evaluate FrontEndTokenExecute["OpenCloseGroup"].

For example, the following toggles the state of the last Cell group in your example Notebook:

cellObj = First@Cells[CellStyle -> {"Input"}, CellTags -> {"test"}];
SelectionMove[cellObj, All, Cell];

You also can play with that group in another way, toggling the visibility of the Input Cell:

cellObj = First@Cells[CellStyle -> {"Output"}, CellTags -> {"test"}];
SelectionMove[cellObj, All, Cell];

The following closes all the Input-Output groups in the Notebook:

cellObjs = Cells[CellStyle -> {"Input"}]
SelectionMove[#, All, Cell]; FrontEndTokenExecute["SelectionCloseAllGroups"]; & /@ cellObjs;

This will open them:

cellObjs = Cells[CellStyle -> {"Output"}];
SelectionMove[#, All, Cell]; FrontEndTokenExecute["SelectionOpenAllGroups"]; & /@ 

Toggle the visibility of the Input Cells in the Input-Output groups:

cellObjs = Cells[CellStyle -> {"Output"}]
SelectionMove[#, All, Cell]; FrontEndTokenExecute["OpenCloseGroup"]; & /@ cellObjs;
  • $\begingroup$ Thanks for your patience. I did think about using FrontEndTokenExecute["OpenCloseGroup"], but was not able to select all input-output groups (and only those). Is there a way? (Also, please see Edit #2.) $\endgroup$
    – Alan
    Aug 31, 2015 at 11:58
  • $\begingroup$ @Alan I have extended the answer with working approach. I should warn that it rely upon undocumented details of behavior of "OpenCloseGroup", "SelectionCloseAllGroups" and "SelectionOpenAllGroups" which can change in future versions of Mathematica. $\endgroup$ Aug 31, 2015 at 13:53

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.