|
Only the
first
nine parts of the Basic Tutorial are included in this draft.
Mathematica Introductory Tutorial (Part 6 of 10)
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 evaluate , the result will be formatted using the notation of traditional mathematics.
![[Graphics:Images/Basic6_gr_3.gif]](Images/Basic6_gr_3.gif)
![[Graphics:Images/Basic6_gr_4.gif]](Images/Basic6_gr_4.gif)
You can also enter your input using typeset notations. For example, you
could enter rather than . One way to enter is to press CTRL-@ (press the @ key while holding down the control key) and then type . You can then evaluate that input just as you would evaluate any other input.
![[Graphics:Images/Basic6_gr_9.gif]](Images/Basic6_gr_9.gif)
![[Graphics:Images/Basic6_gr_10.gif]](Images/Basic6_gr_10.gif)
Mathematica can also display a variety of characters commonly used in mathematics and engineering, such as greek characters, which you can use in your input. Just as with built-in functions, some characters like have special meaning when used in input.
![[Graphics:Images/Basic6_gr_12.gif]](Images/Basic6_gr_12.gif)
![[Graphics:Images/Basic6_gr_13.gif]](Images/Basic6_gr_13.gif)
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.
When Mathematica first launches, it opens a palette window displaying commonly used typesetting forms and characters called the BasicInput palette. If it's not already open, you can open this palette by selecting BasicInput from the Palettes submenu of the File menu.
Palette windows contain buttons which perform some action when you click them. Clicking on the buttons in the BasicInput 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 that palette, , you will get a square root symbol in your notebook.
![[Graphics:Images/Basic6_gr_15.gif]](Images/Basic6_gr_15.gif)
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,
![[Graphics:Images/Basic6_gr_16.gif]](Images/Basic6_gr_16.gif)
fill in the placeholders,
![[Graphics:Images/Basic6_gr_17.gif]](Images/Basic6_gr_17.gif)
select the fraction, and click the square root button to create something like this.
![[Graphics:Images/Basic6_gr_18.gif]](Images/Basic6_gr_18.gif)
For more information on using palettes, see the Getting Started document for your plaform: Windows, Macintosh, or X.
The BasicInput palette provides you with the most commonly used typeset forms: superscripts, subscripts, fractions, roots, matrices, and common characters. Other built-in palettes (BasicTypesetting, InternationalCharacters, CompleteCharacters), give more extensive libraries of preformatted 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 typesetting 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 CTRL key and pressing one other key. For example, to
create a square root (or radical), you can type CTRL-@ or
CTRL-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 CTRL-/
(instead of
Shift-/ for the one dimensional version), and superscripts are typed using
CRTL-^ or CTRL-^ (instead of just ^, which is typically entered as
Shift-^). Here is a grid of the most common typeset forms and
their keyboard equivalents.
|
Radical
|
|
|
|
Fraction
|
|
|
|
Superscript
|
|
|
|
Subscript
|
|
|
|
Above
|
|
CTRL-7
|
|
Below
|
|
|
|
|
CTRL-RETURN
|
|
|
|
|
|
CTRL-5
|
For more assistance with keyboard shortcuts for typeset expressions, see the help files for the Expression Input submenu of the Edit menu, or the 2D Expression Input information.
To type a special character such as 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 Mathematica Book. For example, typing \ [Pi] results in a character, while \ [GothicCapitalZ] yields .
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 ESC (the escape key), type the
alias, and then press ESC again to complete the character. For
example, can also be typed as ESCpESC, and as ESCgoZESC. Again, see The Mathematica Book to learn character
aliases. If you are familiar with the names given to these characters in HTML, , 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. In order to do this you should first create an array of empty buttons. Select Create Table/Matrix/Palette in the Input menu. Click the radio button next to Palette, and choose the dimensions for your array of buttons. Then click OK; the array will paste into your notebook.
Now you should fill in the buttons with the typeset forms you wish to have
on your palette. If you want to include places to fill in your
data, or places where data will be inserted automatically, use □ or
▪ respectively as discussed in a previous
section. You can type these characters using their long
names--\ [Placeholder] and \ [SelectionPlaceholder]--or their aliases--
ESCplESC and ESCsplESC.
To put this array of buttons into its own palette window, select the cell and choose Generate Palette from Selection from the File menu. Clicking the buttons in the palette will not work. To save the palette, click the close box and then save it as you would any other notebook.
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 Format 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 , and what typesetting structures correspond to a fraction and a radical.
![[Graphics:Images/Basic6_gr_56.gif]](Images/Basic6_gr_56.gif)
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 manually 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
you will see this is stored as
![[Graphics:Images/Basic6_gr_57.gif]](Images/Basic6_gr_57.gif)
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
![[Graphics:Images/Basic6_gr_58.gif]](Images/Basic6_gr_58.gif)
The display should change accordingly.
You can browse the options available in the various typesetting boxes in the option inspector documentation.
Exercises
Excercise 6.1 Entering a typeset expression
Enter the equation using notation for the square root and superscripts for the exponents. The result should look like .
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.
![[Graphics:Images/Basic6_gr_62.gif]](Images/Basic6_gr_62.gif)
Exercise 6.3 Adding entries to a matrix
Add one row and one column to each matrix in this matrix dot product. Use for the diagonal elements in both matrices, use for the off-diagonal elements in the first matrix, and use for the off-diagonal elements in the second matrix. Evaluate the matrix dot product and display the result in .
![[Graphics:Images/Basic6_gr_67.gif]](Images/Basic6_gr_67.gif)
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 NumberForm so that the numbers are displayed with no more than two digits to the right of the decimal point.
![[Graphics:Images/Basic6_gr_68.gif]](Images/Basic6_gr_68.gif)
|
2.372e-7
|
|
3407.e
|
|
-970.6e
|
|
-0.00135e
|
|
193.9e
|
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.
![[Graphics:Images/Basic6_gr_69.gif]](Images/Basic6_gr_69.gif)
The resulting display should be similar to this.
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.
![[Graphics:Images/Basic6_gr_82.gif]](Images/Basic6_gr_82.gif)
|
|
x
|
y
|
z
|
|
1
|
3.59`*^-6
|
43.2`
|
109
|
|
2
|
4.61`*^-6
|
108.`
|
112
|
|
3
|
4.9100000000000004`*^-6
|
297.5`
|
117
|
|
4
|
5.13`*^-6
|
732.1`
|
128
|
|
5
|
6.33`*^-6
|
2110.`
|
115
|
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 expressions, 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.
![[Graphics:Images/Basic6_gr_83.gif]](Images/Basic6_gr_83.gif)
Finally, modify the following input so that the label is and change the coordinates of the label so that it does not fall on top of the line in the plot.
![[Graphics:Images/Basic6_gr_85.gif]](Images/Basic6_gr_85.gif)
![[Graphics:Images/Basic6_gr_86.gif]](Images/Basic6_gr_86.gif)
![[Graphics:Images/Basic6_gr_87.gif]](Images/Basic6_gr_87.gif)
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 CTRL(CTRL or CTRL9CTRL. When you're finished
with
your inline cell, press CTRL)CTRL or CTRL0CTRL 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 is the sum of the powers of the divisors of . The function gives the total number of divisors of , and if often denoted . The function , equal to the sum of the divisors of , is often denoted .
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. Use a paste button from the Create Button submenu of the Input menu.
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.
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.
|