Function Repository Resource:

AddStyleToNotebook

Source Notebook

Add a style to a notebook's stylesheet

Contributed by: Brian Van Vertloo

ResourceFunction["AddStyleToNotebook"][nbobj,stylename,{sty1,sty2,}]

adds stylename, defined by the styi, to nbobj.

Details and Options

A private stylesheet is created for the notebook, if necessary.
The new stylesheet for the notebook is returned.
Inherit from existing styles by including StyleDefinitionsname or StyleDefinitionsStyleData[name] in the list of styles styi.
Only one style can be inherited by each added style using this function; specifying a new inheritance will overwrite the previous one.

Examples

Basic Examples  (3) 

This style is not yet defined:

In[1]:=
CellPrint[Cell["abcd", "MyStyle"]]

Add the style:

In[2]:=
ResourceFunction["AddStyleToNotebook"][EvaluationNotebook[], "MyStyle", {FontSize -> 14, FontFamily -> "Arial"}];

Use it:

In[3]:=
CellPrint[Cell["abcd", "MyStyle"]]

Scope  (1) 

Specify a style that inherits from an existing style:

In[4]:=
ResourceFunction["AddStyleToNotebook"][EvaluationNotebook[], "MyTextStyle", {StyleDefinitions -> StyleData["Text"], FontColor -> Red}];
In[5]:=
CellPrint[Cell["abcd", "MyTextStyle"]]

Possible Issues  (1) 

Only one existing style can be inherited:

In[6]:=
Cases[ResourceFunction["AddStyleToNotebook"][EvaluationNotebook[], "Test", {StyleDefinitions -> "Text", FontColor -> Blue}], Cell[StyleData["Test", __], __], Infinity]
Out[6]=
In[7]:=
Cases[ResourceFunction["AddStyleToNotebook"][EvaluationNotebook[], "Test", {StyleDefinitions -> "Title", FontColor -> Blue}], Cell[StyleData["Test", __], __], Infinity]
Out[7]=

Publisher

Brian Van Vertloo

Version History

  • 1.0.0 – 02 December 2020

Related Resources

License Information