19
$\begingroup$

Recently I come back to the problem of cell grouping and performed extensive search on this site and on MathGroup archive for information on how to use the possible values of the CellGroupingRules option. I have found surprisingly little: there are only two rather old MathGroup posts (both I link and cite in this answer) and almost nothing more.

The first is 2000 year post by P.J. Hinton (Wolfram Research) which seems to be outdated in many respects. For example, it states that

"InputGrouping", "OutputGrouping", and "GraphicsGrouping" don't group with any cells that appear after them.

But currently it isn't true: "InputGrouping" groups both with "OutputGrouping" and "GraphicsGrouping" appearing after it, and "GraphicsGrouping" groups with itself. This can be proven as follows:

rulesList = {"InputGrouping", "OutputGrouping", "GraphicsGrouping", 
   "GraphicsGrouping", "GraphicsGrouping", "OutputGrouping", "OutputGrouping"};
Do[CellPrint[
  Cell[ToString[rule, InputForm], CellGroupingRules -> rule, FontSize -> 16, 
   FontFamily -> "Courier", CellFrame -> True, 
   CellBracketOptions -> {"Thickness" -> 5, "Widths" -> {50, 18}, 
     "Color" -> Red}]], {rule, rulesList}]

screenshot

Also cited post states (emphasis is mine):

Grouping rule names that use strings only include "InputGrouping", "OutputGrouping", and "GraphicsGrouping".

But with Mathematica 10.4.1 I get a suggestion to use the form {"InputGrouping", 30}:

screenshot

This form is accepted without warnings for the all grouping rule names listed in the last citation. I wasn't able to figure out how it affects cell grouping: looks like the integer argument is simply ignored. But if the latter is true, why is this form suggested at all?!

Also that post provides no information about new in version 6 "GroupTogetherGrouping" and "GroupTogetherNestedGrouping".

The second is 2007 year post by Derek who summarized own findings on the subject. Unfortunately this post is written in a rather clumsy way, contains a couple of wrong conjectures and essentially adds nothing to the old 2000 year post by P.J. Hinton.

On this site I found this answer by Kyle Keane (Wolfram Research) who briefly mentions that "GroupTogetherNestedGrouping" is intended

... to stay in the same grouping space as list stuff normally resides (look into the Default stylesheet at "Styles for Body Text > Display > Lists > Bulleted").

Unfortunately this is all what he said and no examples demonstrating how it can be used are given.

The question

Is there any manual on the use of the CellGroupingRules option? If not, could anyone summarize own experience of working with this option and give some enlightening examples of use?


Addendum: usage statistics

I grepped all the *.nb, *.cdf and *.m files in the Mathematica 10.4.1 installation folder using PowerGrep with regular expression CellGroupingRules\s?->\s?(".+?"|{.+?}) (total 24776 matches in 10398 files) and collected the following statistics:

  • For the {"SectionGrouping", _Integer} form the second argument may be negative, for example the form {"SectionGrouping", -5} is found 28 times.
  • The form {"SectionGrouping", Inherited} is found 100 times and the form {"TitleGrouping", Inherited} is found 60 times. They are found only inside of Palettes.
  • "GroupTogetherGrouping" is more often used without quotes as GroupTogetherGrouping (120 times vs 1215 times correspondingly).
  • "GroupTogetherGrouping" and "GroupTogetherNestedGrouping" are never used directly, they always present inside of the {type, n} form with n being a number.
  • The form {"GraphicsGrouping", 0} is used in the "PublicationDefault.nb" stylesheet for the style "SingleLine" and also in the "Monograph.nb" stylesheet for the style "FigureCaptionLabel" and in some other places (total 21 times). The forms {"InputGrouping", 20100} and {"OutputGrouping", 20100} are used only in the file ".\SystemFiles\Components\MUnit\FrontEnd\StyleSheets\MUnit\MUnit.nb". The types "InputGrouping", "OutputGrouping" and "GraphicsGrouping" are used directly in the all other places.
  • There are 70 cases of {$CellContext`GroupTogetherGrouping, 10000.} and 21 cases of {FrontEnd`Private`GroupTogetherGrouping, 999.}.

Just for the fun I also grepped the installation folder of Mathematica 5.2 and found that the form {GroupTogetherGrouping, 10000.} is used in the "Reference.nb" stylesheet, and the type "GroupTogetherNestedGrouping" is used many times in different files. So these types actually aren't new in version 6: they just aren't listed in the Options Inspector of version 5.2.

$\endgroup$
4
  • 3
    $\begingroup$ Nice question. I have wondered about some of this but never invested the time to try to find out. For the sake of site organization these are fairly related: (3005), (6015) (But in no way answer your question.) $\endgroup$
    – Mr.Wizard
    Jun 17, 2016 at 10:46
  • 1
    $\begingroup$ Related Wolfram Community thread: "StyleSheets from scratch: Documentation on CellGroupingRules?" At the moment of writing of this comment this thread contains no more than current rather scarce built-in Documentation... $\endgroup$ Jun 17, 2016 at 11:59
  • $\begingroup$ Thanks for adding your research on this. $\endgroup$
    – Mr.Wizard
    Jun 23, 2016 at 11:06
  • $\begingroup$ Tangentially related: how cell grouping interfere with CellMargins. $\endgroup$ Aug 29, 2017 at 7:56

1 Answer 1

7
$\begingroup$

You've got a voluminous question, so maybe this is contained in it (I did check, but I'm also dumb), but here's what I've found:

"TitleGrouping"

"TitleGrouping" is distinct from "SectionGrouping" as subgroups are not formed.

{"TitleGrouping", n} groups the following:

  • {"TitleGrouping", m} such that m > n
  • {"SectionGrouping", m} such that m > n
  • {"GroupTogetherGrouping", m} such that m > n
  • "InputGrouping" / {"InputGrouping", n}
  • "OutputGrouping" / {"OutputGrouping", n}
  • "NormalGrouping" / {"NormalGrouping", n}
  • "GraphicsGrouping" / {"GraphicsGrouping", n}

"SectionGrouping"

Base grouping everyone knows, {"SectionGrouping", n} groups the following:

  • {"TitleGrouping", m} such that m > n
  • {"SectionGrouping", m} such that m > n
  • {"GroupTogetherGrouping", m} such that m > n
  • "InputGrouping" / {"InputGrouping", n}
  • "OutputGrouping" / {"OutputGrouping", n}
  • "NormalGrouping" / {"NormalGrouping", n}
  • "GraphicsGrouping" / {"GraphicsGrouping", n}

"NormalGrouping"

No grouping, as far as I can tell

"GroupTogetherGrouping"

{"GroupTogetherGrouping", n} groups the following:

  • {"GroupTogetherGrouping", n}

"GroupTogetherNestedGrouping"

{"GroupTogetherNestedGrouping", n} groups the following:

  • {"GroupTogetherNestedGrouping", m} such that m >= n
  • {"GroupTogetherGrouping", m} such that m > n

"InputGrouping"

{"InputGrouping", n} == "InputGrouping" groups the following:

  • "OutputGrouping" / {"OutputGrouping", n}
  • "GraphicsGrouping" / {"GraphicsGrouping", n}

"OutputGrouping"

{"OutputGrouping", n} == "OutputGrouping" groups nothing as far as I can tell

"GraphicsGrouping"

{"GraphicsGrouping", n} groups the following:

  • {"GraphicsGrouping", m} such that m >=n

Notes:

I've never found myself having to use anything other than "Section" and the "GroupTogether*" styles. I commonly use {"GroupTogetherGrouping", 0} on things like delimiters that should break up all cell grouping. Of course they group with each other, but generally I use "OverlapContent"->True anyway.

$\endgroup$
3
  • $\begingroup$ I used to know but I forgot, what does "subgroups are not formed" mean? $\endgroup$
    – Kuba
    Oct 24, 2017 at 6:21
  • 1
    $\begingroup$ Ah I meant that like if you have like a "Title" cell and "Subtitle" cell and then a bunch of other cells, you only get one cell group including both the "Title" and "Subtitle", rather than what happens with section styles, where you get a new subgroup for "Subsection" and "Subsubsection" under the enclosing "Section" style. $\endgroup$
    – b3m2a1
    Oct 24, 2017 at 6:24
  • 1
    $\begingroup$ Right, that's what I thought. Yet I was confused because there is a Chapter under Alt+2 which has SectionGrouping and I assumed Subtitle. ;) $\endgroup$
    – Kuba
    Oct 24, 2017 at 6:27

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.