Preview Notebooks / Extra Paclet Features
I decided it was worth it to add some extra features to this thing as it's a good example of what paclets can do for you.
First off, I added a little CreateStylesheetPreview
function that'll take stylesheets and rasterize them to make a preview. e.g.:
CreateStylesheetPreview[
{"Default.nb", "ReverseColor.nb" -> "Custom/CodeNotebook.nb"}
] // CreateDocument
(Read the source code to see how it's implemented. It's not particularly complex stuff.)
Then I made it so that you can "Include"
arbitrary content in your paclet, so we'll add this as a palette. I'll do that as a directory, just to show how it works. Other content can be included directly as files, but I wanted to support both. First we'll create a directory containing the palettes of interest:
Quiet@
CreateDirectory["~/Desktop/Palettes/Custom/",
CreateIntermediateDirectories -> True];
Export[
"~/Desktop/Palettes/Custom/CodeNotebookPreview.nb",
CreateStylesheetPreview[
{"Default.nb", "ReverseColor.nb" -> "Custom/CodeNotebook.nb"}
]
];
then we can bundle and share it like so:
StylesheetShare[
sheets[[1]],
"Includes" -> {
"~/Desktop/Palettes/Custom" -> "FrontEnd/Palettes/Custom",
"~/Desktop/StylesheetShare.wl"
},
"PackageContext" -> {"StylesheetShare`"}
]
CloudObject["https://www.wolframcloud.com/obj/b3m2a1.testing/Paclets/CodeNotebook-1.0.0.paclet"]
You'll notice I also included the package that implements this stuff in there, just for the heck of it.
When you install it, since I didn't bump the "Version"
in the Options
, if you have an old version installed you'll need to install it like so:
StylesheetInstall["CodeNotebook", "IgnoreVersion" -> True]
Paclet[CodeNotebook, 1.0.0, <>]
Once it's installed you'll see two changes from before, first, in the palettes menu we have this:
which just opens up that preview notebook from before.
Second, we can find that installed package:
FindFile["StylesheetShare`"] // StringTrim[#, $UserBasePacletsDirectory] &
"/Repository/CodeNotebook-1.0.0/Include/StylesheetShare.wl"
And so at that point you could just do <<StylesheetShare`
to load the package
If you want to distribute multiple packages you can do that by adding their names to the "PackageContext"
list.
Original
Wrote up a package to do the sharing.
First load the package from GitHub:
Get["https://github.com/b3m2a1/mathematica-tools/raw/master/StylesheetShare.wl"]
This exposes two functions, StylesheetShare
and StylesheetInstall
Next get some sheets to share. Here are a few that are already in a package of mine:
stylesheetsDir =
"~/Documents/Wolfram Mathematica/Applications/BTools/FrontEnd/StyleSheets/BTools";
sheets =
FileNames[
"*.nb",
stylesheetsDir
]
(* Out:
{
~/Documents/Wolfram Mathematica/Applications/BTools/FrontEnd/StyleSheets/BTools/CodeNotebook.nb,
~/Documents/Wolfram Mathematica/Applications/BTools/FrontEnd/StyleSheets/BTools/CodePackage.nb,
~/Documents/Wolfram Mathematica/Applications/BTools/FrontEnd/StyleSheets/BTools/CodePackagePlain.nb,
~/Documents/Wolfram Mathematica/Applications/BTools/FrontEnd/StyleSheets/BTools/DocGen.nb,
~/Documents/Wolfram Mathematica/Applications/BTools/FrontEnd/StyleSheets/BTools/MarkdownNotebook.nb,
~/Documents/Wolfram Mathematica/Applications/BTools/FrontEnd/StyleSheets/BTools/SyntaxHighlighting.nb
}
*)
Then we can share a single sheet:
StylesheetShare[
sheets[[1]]
]
CloudObject["https://www.wolframcloud.com/obj/b3m2a1.testing/Paclets/CodeNotebook-1.0.0.paclet"]
And then install that:
StylesheetInstall[
"CodeNotebook",
"WolframID" -> "b3m2a1.testing"
]
Paclet[CodeNotebook,1.0.0,<>]
Or you can share the entire directory:
StylesheetShare[
stylesheetsDir,
"Name" -> "MySheets"
]
CloudObject["https://www.wolframcloud.com/obj/b3m2a1.testing/Paclets/MySheets-1.0.0.paclet"]
There are a bunch of little settings you can use in StylesheetShare
if you want:
Options[StylesheetShare]
{"Version" -> "1.0.0", "Name" -> Automatic, "Creator" -> Automatic,
"Description" -> "A stylesheets paclet",
"BuildDirectory" :> CreateDirectory[], "MenuName" -> "Custom",
"PacletsRoot" -> "", Permissions -> "Public", AppearanceElements -> All,
AutoCopy -> False, CloudObjectNameFormat -> Automatic,
CloudObjectURLType -> Automatic, IconRules -> Automatic,
MetaInformation -> {}, SharingList -> {}, SourceLink -> Automatic}
But that should be enough to get you started