Background: I'd like to put together a little utility to automate publishing my notebooks to CDF. Right now this involves three steps:
- Copy the current stylesheet definitions (by selecting Format->Edit Stylesheet..., opening up my custom stylesheet, and copying all cells using Ctrl-A), switch the style to the
Defaultstyle (by selecting it in Format->Stylesheet), and pasting the custom definitions back into the notebook's private stylesheet (by selecting Format->Edit Stylesheet... and pasting the definitions I had copied before in there). The result of these steps is a notebook that has its style definitions "baked in", so it's portable, which is the crucial part, of course.
- Remove all input cells - Easy, I have the code for that
- Export the notebook in the appropriate CDF format - Also easy, I just use CDFDeploy
Question: So the issue is item 1, where I have trouble figuring out how to do these steps programmatically. I think I know how to read in the Stylesheet I want (well, at least as long as it's always the same, then I can open the notebook file associated with it; ideally my command would automatically find the right notebook file, or even get the definitions from memory, but I don't even know if that's possible), but how do I get the style definitions inserted into the notebook's private stylesheet? I see there's commands to switch to different stylesheets, but I haven't found a command to insert stylesheet definitions in the notebook's local ("built-in") stylesheet.
I think this is different from what the code here does; the solution there mentions as an assumption that "the parent stylesheet (myparent.nb) of private stylesheet for a notebook is not a built in stylesheet; and that the stylesheet has one or more custom styles that inherit from myparent.nb". The second one of these does not apply to my situation. The private stylesheet of my notebooks is usually empty, and thus does not inherit anything from anywhere.