Skip to main content

Section 35.3 Text Cells and Code Cells

A notebook is a flat list of cells, of just two kinds: formatted text, and executable code. Each division heading, paragraph, theorem, figure, or similar item becomes a text cell. A <sage> element that is a child of a division becomes an executable code cell.
When a <sage> element sits inside a block—say an <example> with a computation between two paragraphs, or an <exercise> with code in its statement—the block is split into consecutive cells: text, then executable code, then text again. The code may sit at any depth, and every enclosing structure is closed before, and re-opened after, each code cell. Styling draws the pieces together visually, and each cell records its parentage in the notebook’s metadata, so the structure is never lost, merely flattened. A <sage> listing marked as display-only is the exception: it is always presented statically, as in print.
Worksheets and handouts are especially at home in this format: each becomes a notebook a student can complete in place.