You are on page 1of 7

Basic Tutorial (Part 6 of 8)

6 Typeset Editing
In this part of the Basic Tutorial you will learn about:

Ë Typesetting input and output


Ë Entering typset input: palettes
Ë Entering typset input: keyboard
Ë Creating palettes
Ë Underlying cell and box structures
Ë Including typeset expressions in graphics

Typesetting input and output


The Mathematica typeset editor is both an editor for typeset documents and an interface to the
Mathematica kernel. You can use the typesetting capabilities of Mathematica to prepare typeset
documents and to enter input and display output using the same notations that you might find in
technical publications.
By default, Mathematica uses typeset formatting for all output. For example, if you enter and evalu-
ate Sqrt@3D, the result will be formatted using the Ñ notation of traditional mathematics.
Sqrt@3D

You can also enter your input using typeset notations. For example, you could enter 3 rather
than Sqrt@3D. One way to enter 3 is to press ‚Î@Ï (press the @ key while holding down the
control key) and then type 3. You can then evaluate that input just as you would evaluate any other
input.

3
Mathematica can also display a variety of characters commonly used in mathematics and engineer-
ing, such as greek characters, which you can use in your input. Just as with built-in functions, some
characters like p have special meaning when used in input.
Sin@q + 2 pD

Entering typeset input: palettes


For every typesetting construct available in Mathematica, there are a variety of ways to create it in
your notebook. You can use menus to enter typeset expressions, but you will usually use the
keyboard or palettes instead. Palette input is discussed here; keyboard input is discussed in the
next section.
Palette windows contain buttons which perform some action when you click them. Clicking on the
buttons in the palette causes the typeset form to paste into your notebook at the location of your
cursor. For example, if you click the sqare root button in the Basic Math Assistant palette, Ç , you
will get a square root symbol in your notebook.
2 Palette
Basic6.nb windows contain buttons which perform some action when you click them. Clicking on the
buttons in the palette causes the typeset form to paste into your notebook at the location of your
cursor. For example, if you click the sqare root button in the Basic Math Assistant palette, Ç , you
will get a square root symbol in your notebook.

Ñ
The Ñ and É squares in this palette designate places where you can insert your own data. The
outlined square, Ñ, is called a placeholder. Use the tab key to move from one placeholder to the
next in a typeset expression. Typing when a placeholder is selected will replace the placeholder with
what you type.
The black square, É, is called a selection placeholder. If you have some input selected when you
click a button, your selected input will be filled in where the selection placeholder is. This lets you
apply typesetting to part or all of your existing input. If there is no selection placeholder, your data
will be replaced by the button's data.
For example, you can click the fraction button,
Ñ
Ñ
fill in the placeholders,
1
Sin@qD
select the fraction, and click the square root button to create something like this.

1
Sin@qD

For more information on using palettes, see the “Mathematica How To” related to palettes.
The BasicMathInput palette provides you with the most commonly used typeset forms: superscripts,
subscripts, fractions, roots, matrices, and common characters. Other built-in palettes
(WritingAssistant, SpecialCharacters, BasicTypesetting), give more extensive libraries of preformat-
ted typeset forms. In the next section, we look at how to create arbitrary typeset forms from the
keyboard.

Entering typeset input: keyboard


For most typeset forms and special characters, we've just seen how to use palettes to obtain them
in your notebook. If you use the same forms over and over, it may be more efficient to use the
keyboard instead of clicking on a palette. There are keyboard shortcuts for all of the common typeset-
ting forms, and all special characters can be entered from the keyboard as well.
Keyboard shortcuts for typesetting are almost always formed by holding down the ‚ key and
pressing one other key. For example, to create a square root (or radical), you can type ‚Î@Ï or
‚Î2Ï. Just as with clicking the palette button, this will provide a placeholder into which to type your
data.
The keyboard shortcuts for some typeset forms are easy to remember. For example, fractions are
typed using ‚Î/Ï (instead of ˜Î/Ï for the one dimensional version), and superscripts are typed
using ‚Î6Ï or ‚Î^Ï (instead of just ^, which is typically entered as ˜Î6Ï). Here is a grid of the
most common typeset forms and their keyboard equivalents.
Radical Ñ ‚Î2Ï or ‚ÎüÏ
Ñ
Fraction ‚Îê Ï
Ñ
Ñ
Superscript Ñ ‚Î6Ï or ‚Î^ Ï
Basic6.nb 3

Subscript ÑÑ ‚Î - Ï
Ñ
Above Ñ ‚Î7Ï
Below Ñ ‚Î + Ï
Ñ
Ñ
Add Row ‚ÜÁ
Ñ
Add Column HÑ Ñ L ‚Î, Ï
Ñ
ÑÑÑ , Ñ
Ñ
Opposite Position Ñ, ‚Î5Ï
Ñ

For more assistance with keyboard shortcuts for typeset expressions, see the Mathematica tutorial
for Input Sintax.
To type a special character such as p into you notebook, you usually will type the two characters '\['
followed by the character's name, and then a closing ']'. As you type the closing bracket, the string
of characters you typed will be automatically replaced by the corresponding special character. You
can see all the special characters and their names in the Documention Center. For example, typing
\ [Pi] results in a p character, while \ [GothicCapitalZ] yields Zℨ.
Many special characters have aliases you can use to type them more quickly, but they are a little
more difficult to remember. To type a character using its alias, press  (the escape key), type the
alias, and then press  again to complete the character. For example, p can also be typed as
ÂpÂ, and Zℨ as ÂgoZÂ. Again, see the Documentation Center to learn character aliases. If you
are familiar with the names given to these characters in HTML, TEX, or SGML, you may find that the
name is an alias to the character in Mathematica.

Creating palettes
You may find it useful to create palettes that contain typeset forms you use most often. This can be
done either programmatically with the with the CreatePalette Mathematica functionor from a selec-
tion with the Generate Palette from Selection submenu item in the Palettes menu. For more details
please see the tutorial in the Documentation Center.

Underlying cell and box structures


Mathematica saves all the information in a notebook as plain text. Just as every special character
has a textual form (\ [name]), every typeset structure also has a textual form. In fact, everything you
see in the notebook window is stored as text in the notebook file. This text is in the format of a
Mathematica expression. A notebook is really a Mathematica expression with head Notebook, and
each cell is a subexpression with head Cell; the notebook interface formats each cell according to
its corresponding expression.
If you want to know how to type a particular special character used in some cell, or what typesetting
structure is used in a cell, or why a cell doesn't format the way you think it should, it may help to be
able to see the underlying Cell expression. You can toggle between the formatted version of the
cell and the raw Cell expression by selecting the cell and choosing Show Expression from the Cell
menu. (This is analogous to using FullForm to analyse output.) For instance, using this technique
on the following cell, you can discover how to type the character q, and what typesetting structures
correspond to a fraction and a radical.
4 Basic6.nb

1
Sin@qD

You can also edit the Cell expression. When you toggle back to the formatted version, your
changes will be reflected in the display. For example, select the above cell and choose 14 point
from the Size submenu of the Format menu. This changes the display and so it must have changed
something about the Cell expression. Using Show Expression, you see that selecting a new point
size simply adds an option to the cell, namely FontSize->14. You can change this number manu-
ally and toggle back to the formatted cell to view your changes.
Within a cell, the subexpression representing a piece of typesetting has a name that usually ends in
"Box", so they are sometimes collective known as typesetting boxes. Typesetting boxes have
options too. For example, if you look at the cell expression underlying a two-dimensional table such
as
1 2 3
4 5 6
7 8 9
you will see this is stored as
GridBox@881, 2, 3<, 84, 5, 6<, 87, 8, 9<<D

Some options for GridBox control whether to draw a frame around the outside of the grid
(GridFrame), whether to draw lines between the rows (RowLines) or columns (ColumnLines), and
how to align the content of each column (ColumnAlignments). You can alter these options by
interacting with the option inspector, or you can directly alter the cell expression to contain
GridBox@881, 2, 3<, 84, 5, 6<, 87, 8, 9<<,
GridFrame -> 2, RowLines -> 1D
The display should change accordingly.
You can browse the options available in the various typesetting boxes in the option inspector tutorial.

Exercises
Exercise 6.1 Entering a typeset expression
Enter the equation z == Sqrt@x^2 + y^2D using Ñ notation for the square root and superscripts
for the exponents. The result should look like z == x2 + y2 .

Exercise 6.2 Editing a typeset expression


Enter an expression like the one below except with the numerator and the denominator exchanged.
You can enter the new expression either by entering the entire expression or by constructing a
template for the new expression and copying the numerator and denominator from this expression
into that template.

q+ 1-2b

q+ 1+b
Basic6.nb 5

Exercise 6.3 Adding entries to a matrix


Add one row and one column to each matrix in this matrix dot product. Use 1 for the diagonal
elements in both matrices, use x for the off-diagonal elements in the first matrix, and use b for the
off-diagonal elements in the second matrix. Evaluate the matrix dot product and display the result in
MatrixForm.
1 x 1 b
K O.K O
x 1 b 1

Exercise 6.4 Formatting numbers


Correct this input so that all of the numbers are displayed with an explicit exponent (this can be
done by setting the ExponentFunction option to Identity), and add a second argument to Number-
Form so that the numbers are displayed with no more than two digits to the right of the decimal point.
NumberForm@Column@82.372`*^-7, 3407.`, - 970.6`, - 0.00135`, 193.9`<D,
NumberFormat Ø HÒ1 <> "e" <> Ò3 &LD

Exercise 6.5 Formatting a table


Use TableForm and PaddedForm to format the following data in a table so that the numbers in each
column are aligned on their decimal points.
data = 88230., 0., 17.4<, 817., 1.3, 2.9<, 80.031, 0.071, 8.01<, 81.58, 1.1, 0.099<<

The resulting display should be similar to this.


230.000 0.000 17.400
17.000 1.300 2.900
0.031 0.071 8.010
1.580 1.100 0.099

Then, create a GridBox expression with the option ColumnAlignments->"." as another way to do
accomplish the alignment. Use DisplayForm to display the grid.

Exercise 6.6 Editing a box expression


Make a copy of the table that is displayed by this input, open the underlying Cell expression, and
add options in the GridBox expression to draw lines between the rows and the columns of the table
and to draw a frame around the outside of the table.
TableForm@883.59*^-6, 43.2, 109<, 84.61*^-6, 108.0, 112<,
84.91*^-6, 297.5, 117<, 85.13*^-6, 732.1, 128<, 86.33*^-6, 2110.0, 115<<,
TableAlignments Ø Center, TableHeadings Ø 8Automatic, 8"x", "y", "z"<<D

Exercise 6.7 Including typeset output in a plot


Up until now, we have only used StandardForm for typesetting. By default, the Mathematica
notebook interface displays all your input and output in StandardForm. This formats some expres-
sions, like square roots, as you would see them in a mathematics text book. However, it does not
follow other conventions from math texts such as using parenthesis for function application or
italicizing single-letter variable names.
There is another typesetting format, TraditionalForm, that does these things. It also uses a
different font than StandardForm, and contains special formatting rules for a greater number of
Mathematica functions. Because parentheses sometimes mean function application and sometimes
mean multiplication in TraditionalForm, care must be taken when creating TraditionalForm
input. Convert the following StandardForm input cell to TraditionalForm by selecting the cell
and choosing TraditionalForm from the Convert To submenu of the Cell menu.
6 Basic6.nb
There is another typesetting format, TraditionalForm, that does these things. It also uses a
different font than StandardForm, and contains special formatting rules for a greater number of
Mathematica functions. Because parentheses sometimes mean function application and sometimes
mean multiplication in TraditionalForm, care must be taken when creating TraditionalForm
input. Convert the following StandardForm input cell to TraditionalForm by selecting the cell
and choosing TraditionalForm from the Convert To submenu of the Cell menu.

LimitBBesselJ@0, xD + x , x Ø 10F

Finally, modify the following input so that the label is J0 HxL + x and change the coordinates of the
label so that it does not fall on top of the line in the plot.

PlotBBesselJ@0, xD + x , 8x, 0, 10<, Epilog Ø TextB

StyleBBesselJ@0, xD + x , FontSize Ø 18F, 84, 2<, FormatType Ø StandardFormFF

3.0

2.5

2.0 x + BesselJ@0, xD

1.5

2 4 6 8 10

Exercise 6.8 Typesetting within text


We've seen how to use typesetting in input, but you can also use typesetting within text like this
paragraph. When you do this, you create an inline cell which contains your typesetting. By default,
Mathematica uses TraditionalForm formatting rules for inline cells. You can create an inline cell
while typing in a text cell by pressing ‚Î(Ï or ‚Î9Ï. When you're finished with your inline cell,
press ‚Î)Ï or ‚Î0Ï to continue typing text. While you're inside the inline cell, there will be a faint
background color indicating the extent of the inline cell.
Use the keyboard and palettes to type a copy of the following cell.
The divisor function sk HnL is the sum of the k th powers of the divisors of n. The function
s0 HnL gives the total number of divisors of n, and if often denoted dHnL. The function s1 HnL,
equal to the sum of the divisors of n, is often denoted sHnL.

Exercise 6.9 Creating a button


Convert the contents of this cell into a button such that, when the button is pressed, the contents of
the button will be pasted at the current position.
x = r Sin@qD Cos@fD
y = r Sin@qD Cos@fD
z = r Cos@qD

Exercise 6.10 Indenting paragraphs


The ParagraphIndent option specifies where the first line of a paragraph should begin. Setting
this to a positive value will indent the first line by that many points. Use the Option Inspector and
the ParagraphIndent option to indent the first line of this cell (the cell that you are reading) by 24
points.
Basic6.nb
The ParagraphIndent option specifies where the first line of a paragraph should begin. Setting 7
this to a positive value will indent the first line by that many points. Use the Option Inspector and
the ParagraphIndent option to indent the first line of this cell (the cell that you are reading) by 24
points.
Setting ParagraphIndent to a negative value will cause a hanging indent, so that the first line
extends further to the left than the remaining lines. Use the ShowExpression menu item in the
Format menu and the ParagraphIndent option to format this cell (the cell that you are reading)
with a hanging indent of 24 points. This is a common format for references or bulletted or numbered
lists.

You might also like