Module 2: Essential LaTeX Commands
Learning Goals
The learning goals for this module include:
- Learn about the basic command structure of LaTeX.
- Learn some specific commands that are useful for high school mathematics teachers.
- Find out where to look for LaTeX command references.
- Practice using the commands using the Simple Renderer and Command Quiz utilities.
Before You Start
A good understanding of LaTeX comes from appreciating both the problem it is solving and the kind of solution it provides.
- Reflect on some of the symbols and notation that you use when writing mathematics: greek letters, exponents, subscripts, radical signs... can you think of some others?
- Have you used or read about languages used in computer programming? LaTeX is sometimes described as a descriptive markup language. Take a moment to look at the Wikipedia entry on markup languages.
As you work through this module, you can use the Simple Renderer to test commands, and when you feel like assessing how much you have learned, try the Command Quiz.
For each new command you learn, consider building the document that you started for Exercise 1 in module 1.
Essential Commands
In this document, we will describe commands assuming that you are using them within LaTeX's math mode. If you are writing an entire LaTeX document, you need to mark the beginning and end of this mode within your document. In many online environments and simple equation editors, you do not need to do this. Additional details on math mode are provided module 4.
Two Important Characters
Because LaTeX is included directly in documents, there has to be some way to tell the difference between LaTeX commands and normal words within the document. This is what the backslash (\) accomplishes - most LaTeX commands are prefixed by the backslash, which functions as an escape character.
Not all math commands require a backslash. Exponents are created using the carrot (^) and subscripts are created using the underscore(_) without being prefixed by a backslash.
The following snippet shows the use of underscore, carrots and a command requiring backslash (\theta).
x_0 = \theta^2
The other special character(s) that you need to be aware of are the curly braces ({}). These are used to block off a set of LaTeX commands that need to be considered as one unit, or if values need to be provided to be included as part of another command. If you need to include curly braces as part of the displayed math, you must prefix them with a backslash.
The following snippet shows the use of curly braces to create an exponent with more than one symbol.
e^{i\theta} = \cos(\theta) + i\sin(\theta)
This next example shows how to include curly braces in the displayed math by prefixing them with a backslash:
\{\theta \in \textbf{R} | -\pi \leq \theta \leq \pi \}
Finding the Right Command
The above examples used many commands, like \theta, \pi, \leq, and others. There are commands for virtually every symbol and notation that you might need - some of them are obvious, as is the case for the greek letters, and some are memorable, like \leq for "less than or equal to." Generally, you will need to look up commands using a reference. A good listing is available at the Online Encyclopedia of Integer Sequences (OEIS) - an interesting site to check out, if you have the time.
Some commands, like \cos and \sin do not seem to do much - but they do let LaTeX know that cos and sin are not just words, but functions - this causes them to be rendered not italicised, whereas any word or letter without a backslash will be put in italics inside an equation (like the variable x in the examples). In this way, LaTeX is helping to ensure that standard mathematical communication practices are followed. The \textbf is another example of how we can follow mathematical conventions by bolding the letter that represents the set of real numbers.
Fractions
Fractions are difficult to write without the help of something like LaTeX, and also provide a good example of a command that requires parameters. In this case, to write a fraction, we need to provide two values, the numerator and the denominator. We do this in LaTeX like this:
\frac{9}{10}
The two sets of curly braces are required here to supply values for the numerator and the denominator. Of course, we sometimes need to include fractions in more complicated expressions, like this one, which shows the formula for a binomial coefficient:
\binom{n}{r} = \frac{n!}{r!(n-r)!}
\[ \large{\binom{n}{r} = \frac{n!}{r!(n-r)!}} \]
More involved fractions, and continued fractions, are supported by the \cfrac command, whose use provides a good example of nesting commands. For example,
a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2+\cfrac{1}{a_3}}}
\[ \large{a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2+\cfrac{1}{a_3}}}} \]
Radicals
Some LaTeX commands require special parameters that are identified using square brackets. The radical sign is one of these. When used on its own, it is the conventional square root<\p>
y = \sqrt{x}
\[ \large{y = \sqrt{x}} \]
When a value is provided using square brackets, we can display other roots, for example:
\sqrt[n]{x} = x^{\frac{1}{n}}
\[ \large{\sqrt[n]{x} = x^{\frac{1}{n}} } \]
Some More Advanced Notation
To format something like a matrix, we need some way of creating a table structure, and some way of creating large square brackets to surround the table. The need to create Tables in LaTeX occurs in several settings, and matrix mode provides a good example of how they are created. There are several more advanced formatting situations that require a special mode. These modes are indicated by the \begin and \end commands, which take the name of the mode as an argument. In matrix mode, ampersands (&) are used to denote columns or tab-alignments, while the double backslash (\\) is used to denote the end of a row. A matrix then, is created like this:
\left[\begin{matrix} a & b & c \\ d & e & f \\ g & h & i \end{matrix}\right]
\[ \large{ \left[\begin{matrix} a & b & c \\ d & e & f \\ g & h & i \end{matrix}\right]} \]
The \left and \right commands are used in front of a bracket to signal that they should be adjusted to enclose the notation between them.
A similar structure (the align mode) is used to get the correct alignment in multi-line equations. For example:\begin{align} \Delta x & = x_2 - x_1 \\ & = 9-2 \\ & =7 \end{align}
\[ \large{\begin{align} \Delta x & = x_2 - x_1 \\ & = 9-2 \\ & =7 \end{align}} \]
A good overview of more advanced math formatting is provided by the LaTeX Wikibook.
Learn More
- Try out each of the examples above using the Simple LaTeX Renderer. Experiment by changing each example.
- Look over the commands listed on the OEIS wiki. Choose some that you think you might want to use and test them out.
- Give the Command Quiz a try.
- Review the page on Mathematics notation in the LaTeX Wikibook.
Learning Checklist
Before moving on to the next module, take a moment to review the learning checklist.
If there were any items in the checklist that you did not complete, consider reviewing this page again before moving on.
References
Forgues, D. and other OEIS contributors. (2013,2019). List of LaTeX mathematical symbols. from OIES Wiki. Retrieved March 17, 2019 from https://oeis.org/wiki/List_of_LaTeX_mathematical_symbols
Wikipedia contributors. (2019, March 7). Markup language. In Wikipedia, The Free Encyclopedia. Retrieved 19:13, March 17, 2019, from https://en.wikipedia.org/w/index.php?title=Markup_language&oldid=886646213
LaTeX Project. (2019) An introduction to LaTeX. Webpage. Retrieved February 27, 2019 from https://www.latex-project.org/about/
LaTeX/Introduction. (2019, February 4). Wikibooks, The Free Textbook Project. Retrieved March 15, 2019 from https://en.wikibooks.org/w/index.php?title=LaTeX/Introduction&oldid=3514336.