2

Background: I'd like to put together a little utility to automate publishing my notebooks to CDF. Right now this involves three steps:

  1. 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 Default style (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.
  2. Remove all input cells - Easy, I have the code for that
  3. 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.

Pirx
  • 4,139
  • 12
  • 37
  • I'm not sure if this does what I want. I tried the stylesheetSetter function shown in the post you referenced, but can't get it to work. It comes back with error messages: First::nofirst: {} has zero length and no first element., and StringJoin::string: String expected at position 2 in C:\Users\Dietmar\AppData\Roaming\Mathematica\SystemFiles\FrontEnd\StyleSheets\<>First[{}]. – Pirx Oct 03 '16 at 20:18
  • So how does your notebook look? Notebook[{}, ... StyleDefinitions -> "pathToCustomStyles"]? Or does it have StyleDefinitions->Notebook[...]? – Kuba Oct 05 '16 at 19:46
  • It's the latter; all style definitions are in a stylesheet .nb file in the user's local Stylesheets folder. – Pirx Oct 05 '16 at 19:49
  • No, at the end of the notebook file there's a declaration that says StyleDefinitions->Notebook[{ Cell[ StyleData[StyleDefinitions -> "customstylesheetname.nb"]] – Pirx Oct 05 '16 at 19:54
  • I'm sorry, but it looks like I'm not understanding your question(s). Can you rephrase them for me? I realize the fault for the miscommunication is entirely mine... – Pirx Oct 05 '16 at 20:44
  • It's $Failed; the private stylesheet is empty. – Pirx Oct 06 '16 at 10:54
  • @Pirx try CurrentValue[EvaluationNotebook[], StyleDefinitions] and use atKuba so I will be notified about your comment. – Kuba Oct 06 '16 at 11:44
  • @Kuba: That gives the filename of my custom Stylesheet nb file, located in my user Stylesheet folder. – Pirx Oct 06 '16 at 11:48
  • And what is the parent stylesheet of that stylesheet? – Kuba Oct 06 '16 at 15:18
  • @Kuba: It's Mathematica's default one, Default.nb – Pirx Oct 06 '16 at 15:37
  • @Pirx so where are your custom/private styles comming from? – Kuba Oct 06 '16 at 15:45
  • @Kuba: They are all in my Stylesheet file, the one in my user Stylesheet folder; let's call it "CSSPirx.nb" for simplicity; of course it doesn't matter what it's called. – Pirx Oct 06 '16 at 15:48
  • @Pirx CurrentValue[EvaluationNotebook[], StyleDefinitions] = Import@"path/to/custom/styles.nb"? – Kuba Oct 07 '16 at 07:25
  • Hmm, that sounded great, and I think it should have worked, but I get INTERNAL SELF-TEST ERROR: CellStyle|c|1314 Bummer. I reported it to Wolfram. – Pirx Oct 07 '16 at 12:41
  • @Kuba: P.S.: I get this error no matter what Stylesheet I'm trying to import, so it doesn't appear to be an issue with the stylesheet itself. – Pirx Oct 07 '16 at 12:43
  • @Pirx maybe your stylesheets has defects. p.s. sometimes those errors appear but the procedure is completed nevertheless. – Kuba Oct 07 '16 at 12:50
  • No, the error comes up with any Stylesheet I try, even the built-in ones. And, no, the styles do not get imported. I tried, CurrentValue[EvaluationNotebook[], StyleDefinitions] = Import@"C:\\Program Files\\Wolfram \ Research\\Mathematica\\11.0\\SystemFiles\\FrontEnd\\StyleSheets\\Article\\JournalArticle.nb", same error. – Pirx Oct 07 '16 at 13:40
  • @Kuba: Do you see the same error? I tried this starting from a blank notebook using the Default Stylesheet, and loading a Stylesheet that's part of the Mathematica installation. Unless the error somehow depends on some option settings then everybody should see this error on Mathematica 11.0.1. – Pirx Oct 07 '16 at 15:12
  • @Kuba: Sorry, I'll get back to you on this, but something came up so I have to put this on the backburner for now. – Pirx Oct 11 '16 at 20:29

0 Answers0