Long answer: With considerable work, if stylesheets have multiple inheritances.
Short answer: If you have one stylesheet that inherits from a Wolfram stylesheet packaged with Mathematica, then the following will embed the stylesheet myStyleNB
in the notebook myNB
.
SetOptions[myNB, StyleDefinitions -> myStyleNB]
The notebook myNB
should be an open NotebookObject[]
, such as returned by EvaluationNotebook[]
. I usually execute SetOptions[EvaluationNotebook[]...]
and then delete the cell. You could also choose the notebook from the following popup menu:
PopupMenu[Dynamic@myNB, Notebooks[]]
Now, myStyleNB
should be a Notebook[]
expression, such as returned by NotebookGet[]
. Something like this:
Notebook[{Cell[StyleData[StyleDefinitions -> "Default.nb"]],
Cell[StyleData["Section"], FontColor -> RGBColor[0, 0, 1]],
Cell[StyleData["Input"], FontWeight -> "Plain"]},
WindowSize -> {808, 911},
WindowMargins -> {{-1570, Automatic}, {-102, Automatic}},
FrontEndVersion -> "14.1 for Mac OS X ARM (64-bit) (July 16, 2024)",
StyleDefinitions -> "Default.nb"]
If you have both the notebook and the stylesheet open, then you can select each and set the stylesheet with the following:
PopupMenu[Dynamic@myNB, Notebooks[]]
PopupMenu[Dynamic@myStyleNB, Notebooks[]]
(* execute the following AFTER setting both notebooks *)
SetOptions[myNB, StyleDefinitions -> NotebookGet@myStyleNB]