Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Basic Tutorial (Part 5 of 8) : The Notebook Front End

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Basic Tutorial (Part 5 of 8)

5 Using Notebooks
In this part of the basic tutorial you will learn about:

Ë The notebook front end


Ë Basic window operations
Ë Cells and cell operations
Ë Style sheets
Ë Buttons and hyperlinks

The Notebook Front End


The notebook front end serves both as an interface to the Mathematica kernel and as an editor for
documents called notebooks. Although it is possible to use the Mathematica kernel directly, most
interactive use of Mathematica is through the notebook front end.
When you type input into the notebook front end, you are editing a notebook. When you evaluate
your input, the notebook front end sends your input to the Mathematica kernel. The results from the
kernel are returned to the notebook front end and inserted into the same notebook.
Notebooks and the notebook front end can be used for much more than just maintaing a list of
inputs and outputs. You can use notebooks to organize notes, graphs, programs, and calculations,
and to format material for presentations or publications.
The notebook front end looks very similar on Windows platforms as it does on Macintosh and Unix.
The Mathematica notebook file is platform independent and is stored as textual information, which
can easily be exchanged via email or the web with users on any platform.

Basic Windows Operations


To use notebooks and the notebook front end effectively, you should be familiar with basic window
operations on your computer, such as opening and closing windows.
When you first launch Mathematica, an empty untitled notebook window is opened. You can open
another empty untitled notebook window by selecting New from the File menu. By default, all of your
open notebook windows will send their inputs to the same kernel. You can move a notebook window
to a different location on your screen by clicking and dragging the title bar of the notebook. Click and
drag in the resize area at the lower right corner of the notebook window to resize it. If there is more
than one page of information in a notebook, use the window's scroll bar to move to a different
location in the notebook.
You can save and close a notebook window the same way you would in any other application, by
choosing Save or Close from the File menu. The notebok front end will warn you if you try to close a
window that has been changed since it was saved.

Cells and cell operations


2 Untitled-2

Cells and cell operations


All of the information in a notebook is stored in compartments called cells. A cell may contain an
input expression, a paragraph of text, a picture, a section heading, or even other cells. For example,
this paragraph is contained in its own cell, as is the section heading just before it.
Each cell in a notebook window has a cell bracket along the right-side of the window that shows
the extent of the cell. If you want to move a cell to a different location in a notebook, you can select
the cell bracket, select Cut from the Edit menu, and then Paste the cell in its new location. You can
combine cells by selecting two adjacent cells' brackets, and selecting Merge Cells from the Edit
menu.
There are also cell brackets surrounding collections of cells, such as the bracket around all of the
cells in this section. This lets you structure your notebook into sections and subsections. By double-
clicking that bracket, the notebook front end will display only the first cell in that cell group, and show
a downward-facing triangle in the cell bracket indicating that the cell group is closed. Double-click
again to open the cell group. This can be useful for gaining an outline view of your notebook. You
can close or open all the cell groups in the cells you have selected by choosing Open All Subgroups
or Close All Subgroups from the Cell Grouping submenu of the Cell menu.
The display of a cell, including things like which font and size are used, is determined by the style of
the cell. You can find a list of available styles in the Style submenu of the Format menu. This sub-
menu indicates the style of the current cell with a check mark.
A cell's style should indicate its purpose in the notebook. Paragraphs of text should each be in a
Text style cell, an expression to be evaluated should be in an Input style cell, the name of a new
section should be in a Section style cell, etc.
When you create a new cell, Mathematica assumes you want an Input style cell, which are typically
displayed in Courier Bold. You can change a cell's style by selecting the cell bracket and choos-
ing a new cell style from the Style submenu. You can also choose a style from this submenu right
before beginning a new cell, and the notebook front end will create a cell of the style you have
selected instead of an Input style cell.

Style Sheets
Which styles are available and how cells in those styles are displayed is determined by a notebook's
style sheet. A style sheet is itself a notebook that contains style definitions. Different style sheets
will cause the cells of a notebook to display or print or be grouped in different ways. You can change
the style sheet for a notebook to one of built-in style sheets by choosing it from the Style Sheet
submenu of the Format menu. Most built-in style sheets define a common set of styles, but each
has some unique styles too.
All of the built-in style sheets are shared style sheets. Notebooks that get their styles from a shared
style sheet need only store the name of that style sheet. Every time such a notebook is opened, the
notebook front end reads the shared style sheet from your hard drive to determine how to display
the notebook. Shared style sheets are useful if you want a collection of notebooks to use the same
style sheet.
The opposite of a shared style sheet is a local or private style sheet. A private style sheet is stored
within the notebook that uses it, and no other notebook can access those style definitions. You
might use a private style sheet if you are sending your work to someone and want to send a single
notebook instead of a notebook and your custom shared style sheet.
Untitled-2
The opposite of a shared style sheet is a local or private style sheet. A private style sheet is stored3
within the notebook that uses it, and no other notebook can access those style definitions. You
might use a private style sheet if you are sending your work to someone and want to send a single
notebook instead of a notebook and your custom shared style sheet.
To get a private copy of a shared style sheet into your notebook, choose Edit Style Sheet... from the
Format menu. You can also use that menu item to edit a shared style sheet. When editing a shared
style sheet, make sure to save your changes. To discard a private style sheet, choose a shared
style sheet to replace it.
Style sheets can define styles which are used as section heads, automatically numbered equations,
or any other logical or stylistic markup. See the online help for more information on style sheets.

Buttons and Hyperlinks


One of the more flexible constructs in the notebook front end is the hyperlink. A hyperlink is an
active element which takes you to another location when you click it.
To create a hyperlink that opens another notebook or web site, select some text that you want to
make into your active link. Choose Hyperlink... from the Insert menu and click Other notebook or
URL. Click "Browse" to select the target notebook, or type in the web site address to complete the
hyperlink.
To create a hyperlink that opens a particular page of the Documentation Center, first locate the
page manually. Take note of which of the sections it appears in and what is displayed in the browser
field at the top of the window.
Next, select the text that will become the link, and paste it in the white box area after typing “paclet:”
An even more flexible construct is Button. For more information, read the related guides and tutori-
als available in the Documentation Center.

Exercises
Exercise 5.1 Set up a new notebook
Start a new notebook that uses the Article Classic style sheet. Among other things the Article Clas-
sic style sheet includes styles for numbered equations, which will be used in a subsequent exercise.
Type Exercise 5 into the notebook and change the style of the cell to Title.

Exercise 5.2 The option inspector


Set the window title to Exercise 5. The window title is the title at the very top of the notebook win-
dow, above the menu items. This title is controlled by the WindowTitle option, which can be set
using the Option Inspector.
Here is a brief description of how to set the window title using the Option Inspector.
Select the new window. Select Option Inspector... under the Format menu. At the top of the Option
Inspector window, set Scope to notebook so the changes will affect the new notebook. Find the
WindowTitle option in the list of available options. One way to find an option is by typing the name
of the option after Lookup near the bottom of the Option Inspector window. The WindowTitle
option is under Window Properties in the Notebook Options section of the list of available options.
Type "Exercise 5" into the box to the right of WindowTitle in the Option Inspector. When you
press the Á key, the window title of the new notebook should change to Exercise 5.
If the window title does not change, check that the new notebook is selected. The name of the new
notebook, which will normally be an Untitled notebook before the change, should appear to the right
of Window at the top of the Option Inspector window. Check also that Scope is set to notebook.
4 Untitled-2

If the window title does not change, check that the new notebook is selected. The name of the new
notebook, which will normally be an Untitled notebook before the change, should appear to the right
of Window at the top of the Option Inspector window. Check also that Scope is set to notebook.

Exercise 5.3 Add sections and text


Below the Title cell, enter Introduction, Equations, and Solution in three separate cells in the new
notebook, and set the cell style for each cell to Section.
Under the Introduction section, enter the text "This notebook was prepared for Part 5 of the Basic
Tutorial." and set the cell style to Text.

Exercise 5.4 Numbering equations


In the Equations section of the new notebook, enter the following three equations in three separate
cells.
2 y ã 10 - 4 x + x ^ 2

y ã 9 - 5 x + x^2

y ã 1+x

Set the style for these cells to NumberedEquation. A number for each equation should appear in
parentheses near the right side of the notebook.
The equations are automatically numbered in order. If you change the style of the first equation
back to Input, for example, or remove the first equation, the numbers for the other two equations will
be updated automatically.
Styles for numbered equations, tables, figures, and other notebook elements are included in all of
the following style sheets.
ArticleClassic ArticleModern
Classic Classroom
HelpBrowser Report

Exercise 5.5 Cell tags and hyperlinks


By adding cell tags to a cell, you can create a hyperlink that goes directly to that cell, highlighting its
cell bracket. Create a hyperlink that selects the linear equation.
To set up hyperlinks to the equations in the Equations section of the notebook, first add cell tags to
these equations. Select the cell bracket of the cell that contains the second equation
(y ã 9 - 5 x + x^2), and select Add/Remove Cell Tags from the Find menu. This will bring up a
dialog box for editing cell tags. Type "quadratic equation" (without the quote marks) below Cell Tag
in this dialog box, and click Add. This sets "quadratic equation" as a cell tag for this cell.
Repeat this for the third equation (y ã 1 + x), setting "linear equation" as a cell tag for the cell that
contains this equation. When you are finished, close the dialog box.
In the Equations section, enter the text "One of these equations is linear" into a new Text style cell.
Highlight the word linear. Choose Hyperlink from the Insert menu. Under Destination within note-
book, select "Cells with the tag:" and choose linear equation from the list of cell tags. Click OK to
finish.

Exercise 5.6 Cross references


In the Solution section of the new notebook, in a new cell, enter the text "The solution to equations (
) and ( ) can be computed using the Solve function." and set the style of the new cell to Text. The
parentheses will be filled in later with references to the equations.
Untitled-2 5

In the Solution section of the new notebook, in a new cell, enter the text "The solution to equations (
) and ( ) can be computed using the Solve function." and set the style of the new cell to Text. The
parentheses will be filled in later with references to the equations.
Type Solve@8y ã 9 - 5 x + x^2, y ã 1 + x<, 8x, y<D into a new cell below the sentence that
you just entered and evaluate this input to get the solutions of this pair of equations.
The cell tags set up in the previous exercise are necessary for the following exercise to work.
Position the cursor between the first pair of parentheses in the sentence that you entered at the start
of this exercise. Select Create Automatic Numbering Object from the Input menu, and use the
dialog box to select the NumberedEquation counter type and the cell with tag quadratic equation.
When you are finished, click OK to dismiss the dialog box. A number corresponding to the equation
with the matching cell tag should appear at the position of the cursor.
Repeat this process with the cursor between the second pair of parentheses and select NumberedE-
quation and the linear equation cell tag in the dialog box.
The equation numbers that appear between the parentheses in this sentence are updated automati-
cally to match the numbers of the corresponding equations. Clicking the numbers will highlight the
corresponding cell. Automatic updating of equation numbers is useful if you are working on a large
document and want to be sure that the numbers in the text always match the numbers on the
equations, even when equations are inserted, removed, or rearranged.
To test that automatic updating of numbering is working correctly, try changing the style of the first
equation to something other than NumberedEquation, or try inserting another NumberedEquation
cell before the two tagged cells. The numbers in the equation cells and the numbers in the sentence
that you entered should be updated to reflect any changes.
To test that hyperlinks to the corresponding NumberedEquation cells are working correctly, try
clicking the numbers in the sentence that you entered. The selection should jump to the cell that
contains the corresponding equation and the cell bracket should be highlighted.
Finally, link the word Solve to the help browser entry for the function Solve.

Exercise 5.7 Modifying a style sheet


Edit the style sheet so that a frame is drawn around NumberdEquation cells.
To do this, select Edit Style Sheet under the Format menu, and choose Import and Edit Styles from
the resulting dialog box. In the style sheet, select the cell for NumberedEquation and use the
Option Inspector to change the CellFrame option to True. A frame should appear around all of the
NumberedEquation cells.

Exercise 5.8 Style Environments


Change the new notebook so that it displays in a way suitable for classroom presentation. Choose
the shared style sheet Classroom from the Style Sheet submenu of the Format menu. The note-
book front end will ask if you're sure you want to discard the private styles from the previous
exercise.
The Classroom style sheet defines different style environments than ArticleClassic. A style environ-
ment is Mathematica's solution to the paradox that documents that look good on the computer
screen often do not look good when printed, and vice versa.
In every built-in style sheet, there are a few slightly different style definitions for each style. The
main style definition, which is designed to look good on the screen, is modified in other style environ-
ments so that the notebook also looks good in other circumstances. Typical style environments
include Working, Presentation, and Printout. The ArticleClassic style sheet does not define a
Presentation environment.
6 Untitled-2
In every built-in style sheet, there are a few slightly different style definitions for each style. The
main style definition, which is designed to look good on the screen, is modified in other style environ-
ments so that the notebook also looks good in other circumstances. Typical style environments
include Working, Presentation, and Printout. The ArticleClassic style sheet does not define a
Presentation environment.
The notebook front end uses the Working environment while viewing the notebook online, and the
Printing environment while printing the notebook. However, you can change which environment is
used through the Screen Style Environment and the Printing Style Environment in the Format menu.
Change the screen style environment to Presentation.
Find some differences between changing the style environment to Presentation versus raising the
Magnification with the Magnification submenu of the Window menu.

Exercise 5.9 Scope and the Option Inspector


Create a new notebook with some text in a Text cell so that the notebook, the cell, and the text all
have different backgrounds.
Open a new notebook that uses the default style sheet. Create a Text style cell that contains the
text "The colors of the rainbow."
Choose Option Inspector... from the Format menu, and make sure the Scope is set to notebook.
Any changes you make will be applied to the new notebook as a whole. Look up the Background
option, or locate it manually under Display Options with the Notebook Options section, and set it to
some color. Click the icon to the far right to open your platform's color selector. The background for
the entire notebook window should now match the color you specified.
Next, select the cell's bracket, and change the Scope in the Options Inspector to selection. Lookup
the Background option again; this time it will be under Font Options in the Formatting Options
section. Set the cell's background to some new color. You should see the new color as a rectangle
around the selected cell, while the rest of the notebook's background remains unchanged.
Finally, select the contents of the cell (your sentence) and specify a separate background for it. You
should see all three colors in your notebook, indicating the various scopes at which the Background
option has been set.

You might also like