7
$\begingroup$

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).

$\endgroup$
  • 3
    $\begingroup$ FE`Evaluate[FEPrivate`GetPopupList["MenuListStyles"]]//Column but I don't know how to use it for other than parent notebook. (8606) $\endgroup$ – Kuba Sep 24 '17 at 12:50
  • $\begingroup$ @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. $\endgroup$ – Szabolcs Sep 24 '17 at 13:00
  • $\begingroup$ @Kuba Do you know how to make something like this update dynamically, preferably with no kernel interaction? $\endgroup$ – Szabolcs Sep 26 '17 at 9:53
  • $\begingroup$ 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. $\endgroup$ – Kuba Sep 26 '17 at 10:34
8
$\begingroup$

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]
$\endgroup$

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.