Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In a previous question, I said that I wanted to display code as text in "Save as (HTML)". I am closer, but would like to ask the community for a better approach by telling the whole picture.

I did my poor's man mathematica blog (here), which is a Rails app that renders HTML. The HTML comes from Mathematica's "Save as HTML", and the Rails app does some HTML manipulation to get it into the blog, including the CDF bits.

So, within Mathematica, what I do is I generate the graphics cells using special code like

        Plot[Piecewise[{{k, u >= k}, {u, u >= -k && u < k}, {-k, 
            u < -k}}], {u, -2, 2}, AxesLabel -> {"x-t", "\[Psi]"}], {k, 0,
          2}], "Output", CellTags -> "psi.cdf", CellMargins -> 0.]];

which, as you can see, makes sure that the generated Cell has the tag "psi.cdf". Then I hide all the code cells (otherwise they get generated as images by "Save as...".) Then I do "Save as..." (HTML) and the standard HTML generator puts an HTML markup with the "psi.cdf" in it around tagged cells; and later (see below) the Rails app picks it up and transform that HTML bit into the HTML that actually embeds the CDF.

Also, manually, I go to each of such tagged Cells and do "Deploy standalone" to get the "psi.cdf" into the same folder. Then, I upload all files to the server and off you go, the Rails app picks up the HTML markup generated for the tagged cells and replaces that by CDF embedding code and it gets properly displayed inside the blog.

I have some issues:

1) I would like to display the code, for the Manipulate and the other graphics, but -as you can see above- the code is really wrapped into a CellPrint. Ugly, I think. If I ever publish that code it won't make people happy. In an ideal world, I would prefer to use 'plain code' and let the 'publishing' take care of the rest.

2) I would like to get help from the community (get ideas) as to how to use the "Save as (html)" better or if a much controlled way via a 'Publishing Palette' is more appropriate for this. Ideally, I think, only the InputCells should be tagged (if they have Manipulate as output) and the corresponding output cell should be 'deployed' etc automatically. Is this possible?

Any ideas/insights are welcome. By the way, the Rails code is open source (here), not the best code in the world, but...

Thanks in advance for all comments :)


I started working on a palette for this and posting more specific questions. Help will be appreciated:

(1) About grabbing CellTags

(2) Iterates properly, I think, but need to export Output cell to CDF

(3) Funny characters in exported code (This was an old question, which I updated based on latest developments)

share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.