10
$\begingroup$

So I've been playing with the new 11.1 documentation style and I noticed that there's something seemingly odd with the openers.

If we open any doc page:

Documentation`HelpLookup@"TaggingRules"

And look at any of the section openers we see they're something custom:

opener

But they work totally normally. And looking at how they're implemented we see a general pattern like:

Dynamic@
 CurrentValue[EvaluationNotebook[],
  {TaggingRules, "Openers", style},
  Closed]

(where style is sometimes more deeply nested, like "ExamplesSection", "0").

And interestingly we can open and close the groups via:

CurrentValue[EvaluationNotebook[],
  {TaggingRules, "Openers", style}] = Open | Closed

And this gets updated when the cell group is opened and closed by hand, too.

If we copy and paste one of these cells the behavior is preserved, but if we take the cell expression and reprint it using NotebookWrite it no longer works. The cell group will open and close because it has WholeCellGroupOpener->True but the opener won't toggle states and we can't close it via CurrentValue.

If I look at the Cell expressions there's no difference, so what causes this?

Update for clarity:

I expected to see grouping from the automatic grouping that Mathematica applies. I figured the grouping behavior would be handled somehow in the Cell expression because copying one of the CellObjects yielded the opening behavior I originally saw. It turns out the CellObject simply remembered the grouping spec.

$\endgroup$
7
$\begingroup$

If we look at the CellGroup expressions we find our answer.

When we copy the Cell expression, we find the grouping acts in the standard way with Open and Closed being assigned to the state.

However if we look at the grouping for the originals or the copies we get:

Dynamic[
 CurrentValue[EvaluationNotebook[],
  {TaggingRules,"Openers",___},
  Closed
 ]

It's this that updates when the CellGroup is opened or closed and it is this that drives the behavior we observe.

Moreover, we can make a new group thing with this behavior:

CellPrint@
 Cell[
  CellGroupData[{
    Cell["Try Me", "Section",
     WholeCellGroupOpener -> True,
     Background ->
      Dynamic[
       If[
        MatchQ[
         CurrentValue[
          EvaluationNotebook[],
          {TaggingRules, "TryMeState"},
          Closed], True | Open
         ],
        None,
        Gray
        ]
       ]
     ],
    Cell["Now I see", "Text"]
    },
   Dynamic[
    CurrentValue[EvaluationNotebook[],
     {TaggingRules, "TryMeState"}, Closed]
    ]
   ]
  ]

And if we copy that header cell to a new notebook we see it preserves its CellGroup state.

It would be nice if there were a way to know when a CellObject has this kind of hidden state--and if there were a way to specify it in the Cell expression--but I have yet to find a way.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.