Wolfram Computation Meets Knowledge

The Form of a Form

There are a lot of interesting features hidden “under the hood” of the Wolfram Demonstrations authoring notebook, and most of them are new to Mathematica 6. The authoring notebook acts as a stand-alone form, and not only represents a simple new way to standardize information for systematic deployment, but also offers a convenient basis for sharing these subtle but powerful new technical details.

I’m excited by any new features that enhance the document creation process in Mathematica. As an 18-year veteran of the company, I’ve interacted with the notebook front end since Version 2, and have been contributing to the interface and documentation systems since Version 3. I’ve recently taken on new responsibilities for managing some of our web applications, particularly online forms for both internal business and external customer interactions, and I’m eager to insert notebook-based source material and Mathematica controller logic into these systems. We have already done so with the Wolfram Mathematica Documentation Center and the Wolfram Demonstrations Project. Of all these systems, Demonstrations are the most visible to our users from their starting point through administrative stages to ultimate deployment, so let’s dissect the Demonstrations authoring form to expose its hidden talents.

If you haven’t done so already, you can open the authoring notebook from Mathematica’s File menu:

File > New > Demonstration

It might take a moment to open, because it’s being pulled from our website. (If you aren’t internet-connected, it will come from the Mathematica installation layout.) Serving it from the web allows us to make updates independent of Mathematica upgrades. The authoring notebook currently looks like this:

Demonstrations authoring notebook

Right at the top you can’t help but notice the colorful banner and the toolbar. It has no cell bracket, and the notebook window’s vertical scroll bar stops just below it. When scrolling, you’ll see why—the banner and toolbar don’t move. They’re “docked cells” and are applied using the notebook-level option called, you guessed it, DockedCells. The right-hand side of this option is a list of cell expressions.

The first of these docked cells is simply a graphic made into a button, so clicking on it takes you to the Demonstrations web site. The second cell is a row of buttons including a popup menu, one of the many new control objects in Mathematica, many of which are incorporated into the Manipulate feature that is the heart of all Demonstrations.

In the actual content area of the notebook are a number of sections with descriptive text. It looks like a lot of material crammed into this document, but take a look at the underlying cell expression of the Manipulate section. Click the cell bracket and select Cell > Show Expression. You will see:

Cell["", "ManipulateSection"]

Indeed, that’s all there is in most of the notebook. Everything displayed comes from the stylesheet!

The notebook’s style definitions also control what cells are created when you type into various sections. Compare some new text typed under the Manipulate[XXXX,{}] placeholder with new text typed under the Caption section’s XXXX placeholder. Under Manipulate you will get an Input cell, and under Caption a ManipulateCaption cell is created. This behavior is controlled by the DefaultNewCellStyle option, and is complemented by ReturnCreatesNewCell and DefaultReturnCreatedCellStyle, and all behave as their names imply. These options let you create automatic templating in a document by controlling which cell is created when first typing into a notebook, and which cells follow when hitting return or when typing under any particular cell.

Another interesting but obscure feature of the Demonstrations authoring notebook is its use of CellContext, which localizes the symbol space to a cell, style, cell group or—as in this case—notebook. To see this in action, simply evaluate the following under the Initialization Code or Manipulate section:

x = 3

and just evaluate x again to confirm its value is 3, with nothing up my sleeve. In a new notebook evaluate x, and voila, you will get x, because x remains undefined in the global context. This same method is used to localize the context of examples in the Documentation Center.

Everything discussed so far is configured in the Demonstrations stylesheet, which is accessed here:

Format > Edit Stylesheet

Or is it? You can see that you have opened a stylesheet, but there’s hardly anything in it.

Demonstrations stylesheet

This is a new twist on the Mathematica stylesheet mechanism. Mathematica’s new default behavior is to edit stylesheets in a cascading model, similar to the CSS scheme employed by most websites. Since we selected Edit Stylesheet from the menu, the goal here is to make it easy to change any style of a notebook you are working on. You simply choose a style from the drop-down menu or enter the name in the field, which creates a style definition cell, but with nothing configured for it. All options are being inherited from the base definitions notebook, which is linked at the top of the stylesheet. Choose DetailNotes from the popup menu, then select the style definition cell that is created and apply Format > Text Color > Red. That’s it, you’ve just edited the stylesheet. In the original Demonstration notebook, start typing under the Details section and you will see the text is now red.

To actually see all the style definitions for the Demonstrations authoring notebook, click the base definitions stylesheet listing at the top of the editing stylesheet. It will open the actual Demonstrations stylesheet from the Mathematica layout, which is where you can explore all the details I’ve been describing. Good hunting!


Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.