7

How can I programmatically list the available cell styles for the current notebook?

I am looking for the same list displayed in the Format → Style menu (which I know is not the exhaustive list of styles, but it does depend on the current stylesheet).

I need a way that can be used from a palette to get the style list of the currently selected notebook (and dynamically refresh it when selecting a different notebook).

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • 3
    FE`Evaluate[FEPrivate`GetPopupList["MenuListStyles"]]//Column but I don't know how to use it for other than parent notebook. (8606) – Kuba Sep 24 '17 at 12:50
  • @Kuba Thank you! Actually, as you guessed, I want to use it from a palette and dynamically refresh it as a new notebook is selected. – Szabolcs Sep 24 '17 at 13:00
  • @Kuba Do you know how to make something like this update dynamically, preferably with no kernel interaction? – Szabolcs Sep 26 '17 at 09:53
  • There was a question how to create such popup menu, the context was to move menu from formatting toolbar to palette. I dont think fe side solution was provided. Will try to find it/investigate later. – Kuba Sep 26 '17 at 10:34

1 Answers1

8

We can use the undocumented function styleMenuStyles to get the list of styles for a particular notebook:

StyleManager`OpenStyleManager;    (* to autoload symbols *)

EvaluationNotebook[] // NotebookTools`StylesheetsDump`styleMenuStyles // Map[First]

(*
   {"Title", "Chapter", "Subchapter", "Section", "Subsection",
    "Subsubsection", "Text", "Code", "Input", "Output", "Subtitle",
    "Subsubtitle", "Item", "ItemParagraph", "Subitem",
    "SubitemParagraph", "Subsubitem", "SubsubitemParagraph",
    "ItemNumbered", "SubitemNumbered", "SubsubitemNumbered",
    "InlineFormula", "DisplayFormula", "DisplayFormulaNumbered",
    "Program"}
*)

Similar undocumented style-related functions are discussed in (71301).

Internally, styleMenuStyles uses a two-argument form of the function FEPrivate`GetPopUpList that Kuba noted in a comment. Essentially:

FEPrivate`GetPopupList[EvaluationNotebook[], "MenuListStyles"] //
FE`Evaluate //
Cases[_[s_String, _] :> s]
WReach
  • 68,832
  • 4
  • 164
  • 269