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)?
Edit:
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.
FrontEndTokenExecute["SelectAll"]
FrontEndTokenExecute["SelectionCloseAllGroups"]
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
Do[CurrentValue[cell,GroupOpen]=True,
{cell,Cells[CellStyle->{"Input"}]}]
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 *)
FrontEndTokenExecute["SelectAll"]
FrontEndTokenExecute["SelectionOpenAllGroups"]
(* 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.