How can I make a stylesheet that counts subcells?
I think when it's done each time you save the notebook it should be nice enough :)
SetOptions[
EvaluationNotebook[],
NotebookEventActions -> {
{"MenuCommand", "Save"} :> (Scan[
Module[{nr},
SelectionMove[#, All, CellGroup, AutoScroll -> False];
nr = Length @ Select[
SelectedCells[],
Experimental`CellStyleNames[#] === "Input" & (*1*)
];
SetOptions[#, CellDingbat -> "(" <> ToString[nr] <> ")"];
] &
,
Cells[CellStyle -> "Section"] (*2*)
]),
PassEventsDown -> True
}
]
Ad 1. Cell style to count
Ad 2. Cell style whose parent group end "resets the counter"
You can use it in stylesheets too.
Update from Question's Author:
As Kuba's comment fixes the raggedness:
SetOptions[EvaluationNotebook[],
NotebookEventActions -> {{"MenuCommand",
"Save"} :> (Scan[
Module[{nr},
SelectionMove[#, All, CellGroup, AutoScroll -> False];
nr = Length@
Select[SelectedCells[],
Experimental`CellStyleNames[#] ===
"ItemNumbered" & (*1*)];
SetOptions[#,
CellDingbat ->
Cell[BoxData[
PaneBox[
StyleBox[ToString[nr] <> " ",
RGBColor[0.5, 0.5, 0.67, 0.81],
FontFamily -> "Continuum Light", 15],
Alignment -> Right, ImageSize -> 40]],
Background -> White]];] &,
Cells[CellStyle -> "Subsection"] (*2*)]),
PassEventsDown -> True}]