Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Previous section-----Next section

2.11.1 Cells as Mathematica Expressions

Like other objects in Mathematica, the cells in a notebook, and in fact the whole notebook itself, are all ultimately represented as Mathematica expressions. With the standard notebook front end, you can use the command Show Expression to see the text of the Mathematica expression that corresponds to any particular cell.

Show Expression menu item toggle between displayed form and underlying Mathematica expression
ControlKeyLeftModified*RightModified or ControlKeyLeftModified8RightModified (between existing cells)
put up a dialog box to allow input of a cell in Mathematica expression form

Handling Cell expressions in the notebook front end.
Here is a cell displayed in its usual way in the front end.
Here is the underlying Mathematica expression that corresponds to the cell.

Cell[contents, "style"] a cell with a specific style
Cell[contents, "style", options] a cell with additional options specified

Mathematica expressions corresponding to cells in notebooks.

Within a given notebook, there is always a collection of styles that can be used to determine the appearance and behavior of cells. Typically the styles are named so as to reflect what role cells which have them will play in the notebook.

"Title" the title of the notebook
"Section" a section heading
"Subsection" a subsection heading
"Text" ordinary text
"Input" Mathematica input
"Output" Mathematica output

Some typical cell styles defined in notebooks.
Here are several cells in different styles.
Here are the expressions that correspond to these cells.

A particular style such as "Section" or "Text" defines various settings for the options associated with a cell. You can override these settings by explicitly setting options within a specific cell.

Here is the expression for a cell in which options are set to use a gray background and to put a frame around the cell.
This is how the cell looks in a notebook.

option default value
CellFrame False whether to draw a frame around the cell
Background GrayLevel[1] what color to draw the background for the cell
Editable True whether to allow the contents of the cell to be edited
TextAlignment Left how to align text in the cell
FontSize 12 the point size of the font for text
CellTags { } tags to be associated with the cell

A few of the large number of possible options for cells.

The standard notebook front end for Mathematica provides several ways to change the options of a cell. In simple cases, such as changing the size or color of text, there will often be a specific menu item for the purpose. But in general you can use the option inspector that is built into the front end. This is typically accessed using the Option Inspector menu item in the Format menu.

• Change settings for specific options with menus.
• Look at and modify all options with the option inspector.
• Edit the textual form of the expression corresponding to the cell.
• Change the settings for all cells with a particular style.

Ways to manipulate cells in the front end.

Sometimes you will want just to change the options associated with a specific cell. But often you may want to change the options associated with all cells in your notebook that have a particular style. You can do this by using the Edit Style Sheet command in the front end to open up the style sheet associated with your notebook, and then modifying the options for the cells in this style sheet that represent the style you want to change.

CellPrint[Cell[ ... ]] insert a cell into your currently selected notebook
CellPrint[{Cell[ ... ], Cell[ ... ], ... }]
insert a sequence of cells into your currently selected notebook

Inserting cells into a notebook.
This inserts a section cell into the current notebook.

In[1]:=  CellPrint[Cell["The heading", "Section"]]


This inserts a text cell with a frame around it.

In[2]:=  CellPrint[Cell["Some text", "Text", CellFrame->True]]


CellPrint allows you to take a raw Cell expression and insert it into your current notebook. Sometimes, however, you may find it more convenient to give an ordinary Mathematica expression, and then have Mathematica convert it into a Cell of a certain style, and insert this cell into a notebook. You can do this using the function StylePrint.

StylePrint[expr, "style"] create a new cell of the specified style, and write expr into it
StylePrint[contents, "style", options]
use the specified options for the new cell

Writing expressions into cells with specified styles.
This inserts a cell in section style into your current notebook.

In[3]:=  StylePrint["The heading", "Section"]


This creates several cells in output style.

In[4]:=  Do[StylePrint[Factor[x^i - 1], "Output"], {i, 7, 10}]


You can use any cell options in StylePrint.

In[5]:=  StylePrint["Another heading", "Section", CellFrame->True,
FontSize->28]


CellPrint and StylePrint provide simple ways to modify open notebooks in the front end from within the kernel. Later in this section we will discuss more sophisticated and flexible ways to do this.


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: