I've got a single code cell in a notebook with lots of Usage messages in no particular order. I'd like to alphabetize them, but doing it manually would be a nightmare. Is there a way to use AlphabeticSort to automate this task?


Foo::usage="Foo does this.";
Bar::usage="Bar does that.";
Baz::usage="Baz does something else.";

1 Answer 1


Run this code in a cell after your usages cell. Save your notebook before you try it because it is a quick prototype:

NotebookWrite[PreviousCell[], #]& @
BoxData @ 
Sort[#, AlphabeticOrder[#[[1]], #2[[1]]] &][[All, 2]] & @ 
Map[ {Cases[#, RowBox[{sym_, "::", "usage"}] :> sym, Infinity][[1]], #} & ] @ 
DeleteCases[_String] @ 
NotebookRead[PreviousCell[]][[1, 1]]
  • $\begingroup$ Thanks, worked perfectly! $\endgroup$
    – Chris K
    Jun 14, 2019 at 14:56

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.