Is there a way to programmatically reorder the section cells in a notebook alphabetically?
For example:
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityIs there a way to programmatically reorder the section cells in a notebook alphabetically?
For example:
I will try to add a more general function later, meanwhile you can use this procedure:
Module[{cells, data},
cells = Cells[CellStyle -> "Section"];
data = (
SelectionMove[#, All, CellGroup, AutoScroll -> False];
NotebookRead[EvaluationNotebook[]]
) & /@ SortBy[cells, First@NotebookRead[#] &];
Do[
SelectionMove[cells[[i]], All, CellGroup, AutoScroll -> False];
NotebookWrite[EvaluationNotebook[], data[[i]], AutoScroll -> False]
,
{i, Length@cells}
]
]
Cell["Python", "Section", WholeCellGroupOpener->True]
$\endgroup$
"WholeCellGroupOpener"
works but I don't know why :)
$\endgroup$