14

I would like to change the Cell GroupOpener appearance.

Cell GroupOpener

In the present Mathematica design it is too small and can be missed by a reader unfamiliar with Mma. I know, how to change its color through the OptionInspector.

Now, how can I put there something instead of the check-mark that is there at present? For example, a gray triangle that has been there previously, of something more complex, some graphics of my own design

Edit: To answer the question of Silva below: This is how the Cell GroupOpener looks like at my machine operating on Windows XP, Mma 9.0.1.

enter image description here

Now on my other machine with Windows 7 and same Mma version the GroupOpener looks like a tiny check-mark. It is hardly visible and it is more difficult to operate (i.e. to open and close). For example, visually it is difficult to distinguish the closed from the open one. I am sorry, being presently at the machine with the XP I cannot provide an image for the GroupOpener at Win7.

Now, it is not too bad, as long as it concerns myself, this or that GroupOpener presentation is it. However, I am creating documents to give away, and need that inexperienced people would easily identify the GroupOpener and easily operate with it. So I would like to be able to control its appearance.

LCarvalho
  • 9,233
  • 4
  • 40
  • 96
Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96
  • I am not sure I understand what you are asking, but you should look at Opener > Options > Appearance in the Documentation Center where this is discussed. – m_goldberg Apr 14 '14 at 15:40
  • Is this question about changing a notebook's style or is it about controlling the appearance of an Opener control in code? – m_goldberg Apr 14 '14 at 15:43
  • @m_goldberg I guess OP is asking about the Cell GroupOpeners. – Silvia Apr 14 '14 at 15:50
  • 1
    @Alexei I think a screenshot would help to clarify your question. And I think the GroupOpener is disabled by default, so it might be helpful to explain what is this GroupOpener and how to enable them. Also, I can see the Cell GroupOpeners are "check-mark" under Windows, but are they the same under Mac / Linux? In other words, it might be helpful to clarify if your question is OS related. – Silvia Apr 14 '14 at 16:02
  • @Sylvia. On OS X a group opener is a right facing triangle. I think it is stored in /Applications/Mathematica.app/Contents/Resources/RightArrow.icns, and I think one would have to change that icon file to change the appearance of a group opener. However, I am too timid to try the experiment on my system, so I don't know for sure. – m_goldberg Apr 14 '14 at 17:18
  • @m_goldberg I looked around the system files on my Windows, but unfortunately I am unable to find a similar file here :( I think maybe we can construct a homemade opener with Dynamic things. – Silvia Apr 14 '14 at 23:59
  • @m_goldberg I would first of all be able to define the GroupOpener within the StyleSheet. I would be also interested to able to do that without the StyleSheet, say, just through the OptionInspector. As Silvia noted I am asking about Cell GroupOpeners – Alexei Boulbitch Apr 15 '14 at 09:16
  • 1
    I guess it's doable by using Dynamic in CellDingbat or similar options. – Silvia Apr 15 '14 at 11:34

2 Answers2

8

According to the documentation, CellGroupData supports Dynamic-object as its status. So with the help of CellGrouping -> Manual, we can design our own "CellGroup opener". It can be a Button or EventHandler placed in CellDingbat, CellFrameLabels, etc. Here is a simple demostration (tested in Mathematica 9.0.1 and 10.0 pre-release on Windows 8.1):

animation demo for self-made CellGroup opener

openerIconOpen = 
  GraphicsBox[{RGBColor[0.26, 0.59, 0.26], 
    PolygonBox[{{0, -0.25`}, {-0.3`, 0.25`}, {0.3`, 0.25`}, {0, -0.25`}}]}, 
  ImageSize -> 15, PlotRange -> All];

openerIconClosed = 
  GraphicsBox[{RGBColor[0.8, 0.16, 0.17], 
    PolygonBox[{{0.5, 0}, {0, -0.3}, {0, 0.3}, {0.5, 0}}]}, 
   ImageSize -> 15, PlotRange -> All];

cellopenflag$1 = True;
cellopenflag$2 = False;

Clear[openerBoxFunc]
openerBoxFunc[flag_] := TagBox[
                               DynamicBox[If[flag, $CellContext`openerIconOpen, $CellContext`openerIconClosed]],
                               EventHandlerTag[{"MouseClicked" :> (flag = ! flag)}]
                              ]

cellBodys = {
             "This is a Text Cell.",
             BoxData[RowBox[{"Another Text Cell with GridBox: ", GridBox[{{"a", "b", "c"}}, GridBoxDividers -> {"Rows" -> {{True}}, "Columns" -> {{True}}}]}]],
             BoxData[RowBox[{"1", "-", "2"}]],
             BoxData[RowBox[{"-", "1"}]],
             BoxData[DynamicBox[GridBox[{{"cellopenflag$1", "cellopenflag$2"}, {cellopenflag$1, cellopenflag$2}}, GridBoxDividers -> {"Rows" -> {{True}}, "Columns" -> {{True}}}]]]
            };

Notebook[{
   (* Start of group 1: *)
   Cell[CellGroupData[{
      (* Cell 1: *)
      Cell[cellBodys[[1]], "Text",
           CellDingbat -> openerBoxFunc[$CellContext`cellopenflag$1]
          ],
      (* Cell 2: *)
      Cell[cellBodys[[2]], "Text"],
      (* Start of group 2: *)
      Cell[CellGroupData[{
         (* Cell 3: *)
         Cell[cellBodys[[3]], "Input",
              CellDingbat -> openerBoxFunc[$CellContext`cellopenflag$2]
             ],
         (* Cell 4: *)
         Cell[cellBodys[[4]], "Output"]
         },
         Dynamic[$CellContext`cellopenflag$2]
        ]](* <- End of group 2. *)
      },
      Dynamic[$CellContext`cellopenflag$1]
     ]](* <- End of group 1. *),
   (* Cell 5: *)
   Cell[cellBodys[[5]], "Text"]
   }(* <- End of Notebook body. *),
  CellGrouping -> Manual,
  ShowGroupOpener -> False
  ] // NotebookPut
Silvia
  • 27,556
  • 3
  • 84
  • 164
  • This is a neat implementation. Is it possible to design a template with this type of functionality? In my initial attempts, editing a stylesheet complains when trying to add the option CellDingbat -> openerBoxFunc[...] – bobthechemist Jun 19 '14 at 16:58
  • @bobthechemist Thanks! Maybe we can define the openerBoxFunc in the stylesheet. – Silvia Jun 19 '14 at 17:02
  • @bobthechemist After another thought, I think it might be better to post process a completed Notebook than to integrate the function in stylesheet... – Silvia Jun 19 '14 at 17:27
  • @Silvia Great. Is it possible to make analogous thing by hand, rather thjan programmatically. For example, would it be possible to open the background cell code (Sift+Ctrl+E) and edit it such that this functionality would be included? – Alexei Boulbitch Jun 20 '14 at 07:29
  • @AlexeiBoulbitch Thanks for accepting! Unfortunately I don't think it's possible to access CellGroupData[...] by the Shift+Ctrl+E method. Maybe we'll have to deal with it at the Notebook expression level. (That is why I think stylesheet approach will be very hard if not impossible.) – Silvia Jun 20 '14 at 10:06
  • Nice one. @AlexeiBoulbitch Perhaps a palette would be a simpler compromise than trying to do magic with a stylesheet, and would allow you to turn it on and off on the selected cellgroup – Rojo Jun 23 '14 at 07:17
  • @Rojo The truth is I don't really know about how to make magic stylesheets :P I can't see how to set a style (if the status can be called as a "style") for Cell[CellGroupData[ contents , status ]]. – Silvia Jun 23 '14 at 07:24
  • @Silvia hehe, a NotebookDynamicExpression that continuously reparses the whole notebook :D. Speaking seriously, I also doubt it is possible to set the group opener variable by style. Perhaps there's some undocumented event that triggers on each new cell group? Who knows – Rojo Jun 23 '14 at 07:39
  • Or a style with a CellDynamicExpression that runs once, and replaces itself with another style and in the process parses possible cellgroups? All hacks, nothing nice – Rojo Jun 23 '14 at 07:40
  • @Silvia This comment is just to report that I tried to copy-paste the cells with the group opener from your method to another notebook. Copy-pasting is possible, but makes several problems reported below. Altogether they make impossible the use of such a method for large documents. The problems are the following: 1) The group opener in a new document works always together with the initial one. 2) If the group opener is pasted into several places of a new document, all these group openers work synchronously. 3) The copied group openers only show up after the initial code is evaluated. – Alexei Boulbitch Jun 24 '14 at 07:55
  • 1
    @AlexeiBoulbitch The synchronous working is because they share the same cellopenflag$xxx status variables, so we'll need to (programmly) generate unique status variables for each CellGroupData. About issue 3, maybe we can put the initial code in the init.m file of the mma kernel, or as a NotebookDynamicExpression for the notebooks. Also you can consider the TaggingRules method for storing the status. – Silvia Jun 24 '14 at 10:10
1

in the absence of a suitable answer to change the appearance of the cell opener and if the cell does not require user edits, you can set WholeCellGroupOpener to True (Format menu - Option Inspector under Cell Options (ensure you have the cell selected)) or by using the Classroom Assistant palette in the Content drop down menu in the Writing and Formatting section and avoid using the cell opener all together.

  • Thank you for your help, but it is not what I am asking about. In the case I already have put ShowCellOpener->True, I would like to be able to control, how the Group Opener looks like. May I, say, use an arrow instead of the triangle, or a check mark? Or may I fix it to be a triangle both at Windows XP and Windows 7. May I change its color? Red instead of gray? That are the questions. – Alexei Boulbitch Apr 22 '14 at 12:24