Adding interactive text


I have two text style cells as shown in the picture (second one is hidden). Is it possible to add an interactive button so that if someone clicks on that button/text then the second cell's can be toggled between open and hidden?

Alternatively, it is also fine if a mouse-over on a button/text brings up a message saying that there is a hidden cell nearby but I would really prefer to have the toggle thing if it is possible in Mathematica.

Desired Output :- When someone clicks on expand the cell below then the hidden cell is set to open and when it is clicked again then the cell is again hidden.



Posted 2020-06-13T09:54:32.880

Reputation: 339



You could use a button like this:

Button["Toggle cell below", SetOptions[NextCell[], CellOpen -> ! CurrentValue[NextCell[], CellOpen]]]


Posted 2020-06-13T09:54:32.880

Reputation: 96

1You could also make the button label dynamic: Button[Dynamic[If[CurrentValue[NextCell[], CellOpen], "Less", "More"]], SetOptions[NextCell[], CellOpen -> ! CurrentValue[NextCell[], CellOpen]]] – Bob Hanlon – 2020-06-13T14:59:49.603

Both of these work very well. Thank you :) – Nitin – 2020-06-13T15:47:17.240


You can set the option "ShowGroupOpener" to True for the first cell of a cell group to add an Opener to open/close the cell groups. Alternatively, set the option "WholeCellGroupOpener" to True to make the whole cell a behave like a toggler button.

You can do this in two ways:

Manually: Right-click the cell bracket and select Properties to open the Option Inspector notebook. ClickCell Options >> Display Options and change the setting for "ShowGroupOpener".

enter image description here

Programatically: In the first cell of the notebook, using some identifying text for the cells to be modified ("comments" in the example below), execute

SetOptions[NotebookFind[EvaluationNotebook[], "comments", All], 
 "ShowGroupOpener" -> True]

enter image description here


Posted 2020-06-13T09:54:32.880

Reputation: 302 076

This is absolutely perfect. I hope you don't mind that I keep the other answer as the accepted one because that was posted earlier and the contributor is new. – Nitin – 2020-06-14T15:27:37.467