# CDF deployment issues

For a class I am teaching I would like to deploy CDFs on a website (BlackBoard-driven, if it matters), and I am running into two issues at this point:

A) I would like to have the CDFs styled according to a custom stylesheet of mine, but this only seems to work if that stylesheet is present on the target computer. I did follow the workflow suggested here, but I still get a message saying

The stylesheet "" depends upon a stylesheet named "name.nb" which cannot be found by the Wolfram System.

and no styles are applied to the content of the CDF.

B) When someone clicks on the link to a CDF, the results look disastrous: Not only are there no styles applied at all, but the CDF Player toolbar itself is messed up, like so:

I note that this does not happen if I provide a link to a notebook; it's only CDFs that result in the broken CDF Player toolbar.

If I choose "Web embeddable..." during the CDF creation process, things go a little better, in that in this case I get a CDF that seems to have style information embedded. However, the browser plugin opens the CDF such that it fits the entire document in the browser window so no scrolling is required, which makes the CDF (and its toolbar) unreadable. In addition, if I open the CDF file that's created directly, while I do get a properly styled layout, but with all input cells revealed and open.

Ideally, what I would like is for people to see a nice rendering, with styles applied, of the CDF in the same way I see it if I click on the "Open in Player" icon. I guess my question is, what is the secret to producing a usable CDF? Is this possible? The methods provided by the frontend interface certainly do not result in such CDFs.

Update: I spent more time troubleshooting this, and here's my latest findings: I realized that I don't really understand the mechanics of embedding stylesheets into notebooks at all. It appears that somehow, and I really don't know how that happened, I was able to create a notebook that has the stylesheet information embedded. If I open this on a machine with the stylesheet in question, I get a "ding" when opening it, but no error messages, and the styling is applied as it should. However, I have another notebook, that I had thought I had treated the same, and this one insists on the stylesheet being present, or else it will not format correctly.

By now I'm pretty sure that one of the fundamental questions here is: Why the hell is there no straightforward way to embed entire custom stylesheets in a notebook? You know, something as amazingly nifty as a menu item saying "Embed style definitions in this notebook". What this function would do is simply copy all of the style definitions in the notebook's custom Stylesheet into its private style definitions, and then switch the stylesheet in use to the Standard Stylesheet. This way we will have created a portable notebook that will render its styles the same on any machine with a standard Mathematica installation.

I also found that the CDFs produced as "Standalone" or "Web embedded" versions are quite different, and that I get yet a third version if I use the Save button in the CDF player from within the browser. I can find no rhyme or reason behind any of these.

• I encountered the issue with stylesheets and the messed up toolbar as well and my solution was to not define a stylesheet and apply it to my notebook from which I generate a .cdf file but instead just click edit stylesheet and copy/paste in definitions from another notebook. That seems to correctly embed the formatting inside the .cdf file later. – Sascha Aug 31 '16 at 19:26
• @Sascha: Yes, this method works, kind of. So my workflow for this is to create the doc with my custom Stylesheet (so I know what things look like), then, when I'm all done, I switch back to the Default Stylesheet, and then Copy/Paste the entire content of my custom stylesheet as Private style definitions. Of course, like I said above, it's a mystery why Wolfram does not provide a menu item that would perform this function for us. Oh well, I guess as Mma users we're used to having to recode our user interface ourselves... – Pirx Aug 31 '16 at 19:49
• The major remaining question I have is with regards to the difference between web-embedded and regular CDFs. I like the fact that the web-embedded versions have the input cells removed entirely (the stand-alone version does have the input cells included). The problem with the web-embedded version is that it's unreadable when I open the link to such a CDF in my browser. The question is, is it possible to generate a "Stand-alone" CDF that does not show the input cells? – Pirx Aug 31 '16 at 19:55
• You can use this 17441 but if your private stylesheet depends of another custom one then you have to copy that manually anyway. So this question is about browser plugin or cdf player? – Kuba Sep 1 '16 at 5:19

Alright, I am going to answer my own question:

On issue A, a possible workflow is the following:

1. Create the CDF source notebook using the intended custom Stylesheet
2. In the new notebook, switch to Mathematica's Default Stylesheet
3. Open the notebook file for the custom Stylesheet, and copy all of its cells
4. In the new CDF source notebook, go to "Edit Stylesheet..." and then paste all of the cells copied in Step 3 into the Private Style definitions

It's a bloody hassle, and Wolfram should have provided a menu item to do this in the frontend, but it is what it is...

On issue B, it turns out that the function CDFDeploy does what I want, and by default creates a CDF that does not show the input cells. In addition, it allows me to modify the WindowSize of the CDF it creates, which solves the browser issue I saw.

As an aside, the way the CDF display in the browser is handled is very strange. The plugin always scales the document so the window height (as given by WindowSize)fills the available height of the browser window. To do so, it will scale the document just like a Magnification would. There is a magnification button on the toolbar of the CDF plugin, but this has no effect whatsoever. Also, the browser-provided zoom setting has no effect. Thus one really has to play with the WindowSize setting to try and find one that works alright on most computers. My guess is that someone with a high-resolution screen will be in trouble when trying to view a CDF produced in this way on a machine with a standard screen, and vice versa. Well, we already know that Wolfram never bothered to get Mathematica to display correctly on PCs.

• I think that the stylesheet is already embedded in the notebook when you begin to customize the style. A separate file is only created when you install the style (there is a button for this) so it becomes available for other notebooks. The style can't be at the same time in the notebook and in the library, unless it is copied (or linked but link does not work for only part of a file in most OSs). Sascha's method consists in creating a new notebook, copying the old style cells into the new style sheet and NOT install the style so it remains embedded. – Pierre ALBARÈDE Apr 19 '20 at 23:02

I can answer on that:

Why the hell is there no straightforward way to embed entire custom stylesheets in a notebook?

Don't hack this on any important document!

Open the notebook where you want to embed style with a text editor, look for a line like

StyleDefinitions->"myJournalArticle.nb"


Find this file in your system. It could be anywhere in $Path but if you have installed the style it will be in $UserBaseDirectory/Mathematica/SystemFiles/FrontEnd/StyleSheets.

Copy the part NoteBook[___] and paste it in the first notebook instead of "myJournalArticle.nb".

If you like the method, it can probably be automated it in Mathematica with NotebookOpen etc.

This question should be updated because with v12 CDF is supposed to be useless (so writes the CDF save dialog).

• Sorry my answer should have been a comment and conversely. Nevermind. If you want no trouble make you modifications by copying and pasting cells and if you want to understand what is going on check with texteditor what is under StyleDefinitions. – Pierre ALBARÈDE Apr 19 '20 at 23:23