Download the lesson example and open it up in your development environment. The text here is complementary to the source code, and this lesson will mostly be a description of how the source code works. It's probably worth compiling the source code just to get a notion of what the result of each bit of the source code looks like.
Ideally, mathematical layout elements should grow to enclose the things they contain. Square roots and fractions do this automatically, but parentheses and the like don't. An exhibit of poorly sized parentheses is on line 26 of the source code example; the parentheses are standard-text size, even though they enclose fractions whose size (in display-math mode) is considerably larger. Delimiters (parentheses, braces, and so forth) can be designed to resize by using pairs of \left and \right commands. Each of these commands should be followed immediately by the delimiter being resized. This usage appears on line 31 of the example code, where the integral is enclosed by \left( and \right).
If you want to only delimit the left or right side of some expression, you can use \left. or \right. (noting the periods which mean "no delimiter") to indicate the beginning or end of some resizable-delimiter group without actually typesetting a delimiter. Such usages are uncommon but useful: for instance, one notation for evaluating an integral uses an appropriately sized vertical line on the right only; this is shown in line 37 of the source code. Another, more advanced usage, is that the several cases in a piecewise function are enclosed with a curly-brace on the left and no symbol on the right, and this notation is also achieved using a delimiter pair with an invisible right delimiter. This is exhibited on lines 73–79 of the source code.
A lot of the really clever functionality in LaTeX is squirreled away into packages, addons you can use to get additional features. In this chapter we're using four of them, all developed in cooperation with the American Mathematical Society. These packages are amsfonts, which provides some useful fonts, amssymb, which provides additional symbols, amsthm, which has theorem-proving environments, and amsmath, which has a bunch of miscellaneous math-formatting environments. These packages are included on line 10 of the example source code.
The symbols provided by amssymb are listed, like so many other individual commands, in the huge symbol list we've seen previously, this time in Tables 4, 51, 73, 89, 90, 113, 123, 131, 141, 142, 143, 182, 185, 194, 200, 212, 220, 233, 243, 256, 270, 289, and 295; they're also listed in section 7.2 of the AMS symbol/font documentation. Most of the time you're best off looking for symbols you need in LaTeX's core symbols list, but a few useful ones really do need the AMS list, specifically \nmid, which is the symbol for "does not evenly divide". This symbol is used on line 43 of the example source code.
Fonts in math mode have mostly worked the same as fonts in text mode, but with different commands: there's a \mathbf command for putting a symbol in upright boldface and a \mathtt command for writing in typewriter text. There's also a \mathit command for italicized content, but since alphabetical text in math mode is already italicized, there's little reason to use that one. What is occasionally useful, however, is its opposite, \mathrm, used to make "Roman", or upright text. (Incidentally, there is also a \textrm command, which wasn't mentioned in Lesson 2 of the because there's rarely reason to use it, as text is usually upright by default.)
The amsfonts package provides a few new mathematical fonts. The most frequently useful one is \mathbb, which formats letters in a way known as "blackboard bold", which has become the standard formatting used to identify the well-known predefined sets of numbers. Also useful is \mathcal, which produces lightly caligraphic letters, suitable for describing "collections", which are sets of sets. An example of blackboard bold is on line 43 of the source code example, where \mathbb{Z} is used to represent (in keeping with mathematical convention) the integers. The script text suitable for denoting a collection can be seen on line 47, where \mathcal A is used to represent a set of sets. Note that the braces are optional and you can use them or not as fits your comfort level; one of these two examples uses braces, and the other doesn't.
The amsmath package provides a few other very useful commands. It was mentioned previously that you could define your own "log-like" commands for functions not supported by default in LaTeX, like, for instance, the arccotangent (arcsine, arccosine, and arctangent are predefined, but apparently the arccotangent is regarded as esoteric enough to not be defined). A declaration creating a new \arccot command, which typesets the text "arccot" can be seen on line 12 of the source code example. This command is then used on line 51 to typeset an arccotangent correctly in math mode.
Sometimes text needs to be embedded in math for clarity. amsmath provides a straightforward command \text{...} to typeset text while still in math mode. This is used on line 54 of the source file; this is also used, in a more advanced context, on lines 75–77.
Sometimes you want an aligned substructure within a larger equation; one of the most common places this is useful is in defining a piecewise function, where you want to set a function equal to a block which is itself multiline. align* wouldn't do this, or at least not very well; you could kludge it up, but it wouldn't look good. To have a piece of math which you then embed a larger multiline piece of mathematics in, you use the aligned environment, not instead of a displaymath environment, but inside it. The flow of fairly ordinary uses of this type are on lines 73–79 and 109–114 of the source file. These are reasonably complicated syntheses of several things we've seen, so let's look closer at how they're structured. Each begins and ends with the display-math marks \[ and \], and each defines a function or sequence as equal to a piecewise expression. The piecewise expression itself is typeset using an aligned environment, with each case on a separate line followed by a \text command to describe when it's in effect. All lines are aligned to that text describing the conditions, which is why the alignment tab always precedes the \text command. But there's one more decorative detail: a good piecewise function has a curly-brace on the left side, scaled to the number of cases. This is a great use of the resizable delimiters we saw earlier, since the cases themselves are just a very tall block of math, which the brace will resize to contain. So before the case-structure, we add in a \left\{ (remember that braces are special, and a literal brace needs a backslash before it). And we don't want any sort of delimeter on the right, but we do need to close the resizable-delimiter block, so we put \right. after the case block.
The amsthm environment provides ways to typeset theorems (and theorem-like material) as well as their proofs. Proofs are frankly a little bit simpler to illustrate. A proof in lines 99–102 of the source material is enclosed in the proof environment. The result (by default; other packages might modify this display standard) is that the proof is prefaced by the italic header "Proof.", and ended by a right-justified square (a standard symbol for the end of a proof).
Theorem-like things come in all different flavors: propositions, conjectures, theorems, lemmas, corollaries, and so forth, varying wildly with mathematicians' personal styles. So the amsthm environment leaves the definition of them up to you, but gives you a framework for easily defining theorem-like environments. The \newtheorem command, used in the preamble of the source example on lines 13 and 14, defines a new environment, whose name is the first parameter to the command (the second parameter is the text name of the type of theorem-like environment. So in this example, we have two theorem-like environments defined: prop for propositions, and conj for conjectures. We can then use these just like we'd use any other environment, and you can see them in use on lines 96–98 and 106–115. These environments automatically number the individual theorems, and use emphasized text for the body of the theorem. Like all other numbered things, if you were to add a \label command inside the environment, you could then use a \ref to later refer to that result by number.
One additional property of the theorem environment is used on line 106 of the source example. A result proven (or described) elsewhere simply needs a citation rather than a proof. Here a citation is provided as an optional parameter (in square brackets) to the conj environment.
Most errors which can arise with these techniques are similar to those you've already seen: misspelling a command, failing to terminate an environment, and so forth. There are a few specific to resizable delimiters, however.
Write a document which compiles to make a PDF looking like this.