Getting started with LaTeX
The standard method for typing mathematics is to use LaTeX (lay-tech). If you have an aspirations to graduate school, then you'll have to learn how to do this eventually, so you might want to start by learning to type your homework...
LaTeX has two main difficulties for the new learner:
- Production of a finished document is a two-step process: content is first typed in a text file (.tex extension), which is then compiled using the (pdf)latex program to produce an output file (usually a pdf). Standard office programs (e.g. Word) do these steps simultaneously, so this will take some getting used to.
- All mathematics and formatting is typed in code using commands: in LaTeX these begin with a backslash (\).
Here are two methods for how to get started.
1. The Basic Method
Overleaf is a free online LaTeX compiler (others are available). With an account you can easily save, edit and compile a file online. To test things out, try uploading this sample file, which should result in your browser looking like this:
Help with commands can be found via the main menu or directly.
Try reading Learn LaTeX in 30 minutes, in particular Section 10: Adding math to LaTeX.
2. The Traditional Method
Download and install a full (La)TeX distribution. For suggestions based on your operating system see the LaTeX project. To test everything out, download the sample file and open using the editor for your distribution. The picture below shows how things look using the MiKTeX editor (TeXworks) on Windows; to compile the document, select pdflatex from the drop-down menu at the top and hit the green triangle. If you do everything correctly, your screen should look like this
and the file main.pdf will appear in the same folder as main.tex. Any other files produced by the compilation (main.log and main.aux) can be safely ignored. If you attempt to compile faulty code, the log file will typically be displayed to help diagnose the problem.
Tips and Tricks
- Start by editing the sample file, or by downloading and editing other examples. The best way to learn LaTeX is to play with it and see what happens!
- Everything before \begin{document} is the preamble. This contains global formatting commands, packages and shortcuts. You shouldn't need to mess with this until you've played with LaTeX for a while. The amssymb and amsmath packages (lines 5 and 6) make sure you have all the math commands you need to get started.
- The output is typed between the \begin{document} and \end{document} commands. The sample file is set up to make typing homework easy: \begin{enumerate} initializes a numbered list and each \item command starts a new solution using the next number. If you want to override the automatic numbering, try \item[3.14159].
- Mathematics is typed in two ways:
- Inline mathematics is surrounded by $ signs: for example, $\frac{8}{23}$ results in the fraction 8/23, suitably formatted. In the sample file, the first integral is typed inline (\displaystyle merely makes the integral sign larger and clearer).
- Displayed mathematics appears on its own line(s) and is bracketed by \[ ... \]. For example \[\frac{8}{23}\] would print the fraction on a separate line in a larger font. The above truth table is displayed.
\begin{align*} ... \end{align*} produces two lines of displayed mathematics: the ampersand & tells LaTeX where to align the two lines (so the "if and only if" arrows are stacked), and the double-slash \\ creates a new line.
- Several symbols are special. In particular:
- % prefixes comments; these lines are ignored by the compiler.
- The backslash \ indicates the start of a command.
- Pairs of curly brackets { } are used to surround arguments or to bracket content.
- $...$ brackets inline mathematics.
You'll encounter others if you use LaTeX for a long time. Mismatched brackets ({...} or $...$) are the most common reason for compilation errors. If you really need to type any of these characters, use the commands \%, \textbackslash, \{, \} and \$.
- As freeware, LaTeX does not come with standard documentation. Your text editor might have pull-down menus for common commands, but be prepared to search the web if you want to know how to type something. Searching for "latex lists" will bring up examples on how to typeset lists, while "latex table spacing" will teach you how to vary column widths...