We can force FrontEnd to use versioned preferences by turning on the "VersionedPreferences"
option:
SetOptions[$FrontEnd, "VersionedPreferences" -> True];
After evaluating this and restarting Mathematica each version will use its own set of FrontEnd preferences.
One of such preferences is StyleSheetPath
which specifies the list of directories FrontEnd searches to find stylesheets:
CurrentValue[$FrontEnd, StyleSheetPath]
{
FrontEnd`FileName[{"C:\\Program Files\\Wolfram Research\\Mathematica\\11.1\\SystemFiles\\Links\\DataResource\\FrontEnd","StyleSheets"},"PacletManager"->True,"Prepend"->True],
ParentList,
FrontEnd`FileName[{"C:\\Program Files\\Wolfram Research\\Mathematica\\11.1\\SystemFiles\\Components\\MUnit\\FrontEnd","StyleSheets"},"PacletManager"->True]
}
Let us create in $UserBaseDirectory
a directory named "_MyStyleSheets_" with subfolder named according to $VersionNumber
:
CreateDirectory[
FileNameJoin[{$UserBaseDirectory, "_MyStyleSheets_", ToString[$VersionNumber]}]];
Now prepend (!) this folder to StyleSheetPath
. The following permanently changes StyleSheetPath
for the version where you evaluate this (if "VersionedPreferences"
is already set to True
):
SetOptions[$FrontEnd,
StyleSheetPath ->
Prepend[CurrentValue[$FrontEnd, StyleSheetPath],
With[{ver = ToString[$VersionNumber]},
FrontEnd`FileName[{$UserBaseDirectory, "_MyStyleSheets_", ver}]]]];
Now if we create a subfolder "Wolfram" and put there modified "Reference.nb" stylesheet, after restarting the Documentation pages of the current version of Mathematica will use this stylesheet (but not the other installed versions):
CreateDirectory[
FileNameJoin[{$UserBaseDirectory, "_MyStyleSheets_", ToString[$VersionNumber],
"Wolfram"}]];
Export[FileNameJoin[{$UserBaseDirectory, "_MyStyleSheets_", ToString[$VersionNumber],
"Wolfram", "Reference.nb"}],
Notebook[{Cell[
StyleData[StyleDefinitions ->
FrontEnd`FileName[{$InstallationDirectory, "SystemFiles", "FrontEnd", "StyleSheets",
"Wolfram", "Reference.nb"}]]],
Cell[StyleData["NotesSection"],
CellDynamicExpression :>
FrontEnd`Private`SetCurrentValue[
FrontEnd`ButtonNotebook[], {TaggingRules, "Openers", "NotesSection"}, True]]},
StyleDefinitions -> "PrivateStylesheetFormatting.nb"]]
This approach has the advantage that you always know where your custom stylesheets are located, and can easily backup them all at once if you reinstall the OS, transfer data to other computer, share your custom-styled Notebooks with friends etc.