Quick LaTeX Guide
About this page
This page is mostly meant to be a reference for my students, so that they can effectively use $\LaTeX$ to typeset their homework and to write mathematics in thes in Moodle.
For information on using $\LaTeX$ via ScribTeX or installing $\LaTeX$ on your own computer, go to the bottom of this page.
What is LaTeX?
LaTeX (pronounced "lay-tech", or sometimes "la-tech") is a markup language that is the standard for typesetting mathematics.
Special Considerations for Moodle
Plymouth State University's Moodle implements a subset of $\LaTeX$ via jsMath. In ordinary $\LaTeX$, most people would use dollar signs ($\$$) as delimiters (more on this below), but things are intentionally not set up this way in Moodle since there are many circumstances when someone might want to use dollar signs and not typeset mathematics. If you are already familar with the basics of $\LaTeX$, then the only thing you really need to know to use $\LaTeX$ in Moodle is that you must use \(
and \)
as delimiters instead of dollar signs.
The upshot of this is that if you are typesetting in Moodle, everywhere you see an opening (respectively, closing) dollar sign below, you should replace it with \(
(respectively, \)
).
The Basics
You can insert mathematical expressions within your text (i.e., "inline") by using code of the form:
$your-mathematical-expression-here$
Note: If you are typesetting in Moodle, then you should use:
\(your-mathematical-expression-here\)
The pair of dollar signs that frame your mathematical expression are called delimiters and indicate where the expression begins and ends. You must have an opening and closing delimiter.
For instance, this sentence -- which includes the equation $x^{2}+y^{2} = r^{2}$ -- is typeset as
For instance, this sentence -- which includes the equation $x^{2}+y^{2} = r^{2}$ -- is typeset as
Notice that I didn't enclose every individual symbol with dollar signs, but rather the entire string of symbols.
You can also have your mathematical expressions separated from the text and placed on their own line for emphasis. For instance, if you wanted to type:
Here's some fancy mathematics that I don't really understand \[ \log \zeta(s) = s\int_{2}^{\infty} \frac{\pi(x)}{x(x^{s}-1)}~dx = \log \prod_{p} (1-p^{-s})^{-1}. \] Man, that's complicated!
then you'd use the code
Here's some fancy mathematics that I don't really understand
\[
\log \zeta(s) = s\int_{2}^{\infty} \frac{\pi(x)}{x(x^{s}-1)}~dx = \log \prod_{p} (1-p^{-s})^{-1}.
\]
Man, that's complicated!
In this case, we are using the pair of delimiters \[
and \]
as opposed to dollar signs. This works in ordinary $\LaTeX$ and in Moodle.
Here are a few things to keep in mind:
- All inline mathematical notation must be framed by dollar signs (or
\(
and\)
in the case of Moodle). - All displayed mathematical notation (i.e., on its own line and centered) is of the form
\[ math-stuff \]
. - All special symbols in $\LaTeX$ are of the form
\some-command
. Once you've used $\LaTeX$ enough, you can almost guess what the command is for a certain symbol.
Some Examples
Here are a few more examples that illustrate some of the mathematical notation we may want to use:
Expression you want | Code you type |
---|---|
$\int_a^b f(x)\; dx=F(b)-F(a)$ | $\int_a^b f(x)\; dx=F(b)-F(a)$ |
$n \in \mathbb{N} \subseteq \mathbb{Z}$ | $n \in \mathbb{N} \subseteq \mathbb{Z}$ |
$\sum_{i=1}^n i^2=1^2+2^2+ \cdots +(n-1)^2+n^2$ | $\sum_{i=1}^n i^2=1^2+2^2+ \cdots (n-1)^2+n^2$ |
$\sqrt{2} \notin \mathbb{Q}$ | $ \sqrt{2} \notin \mathbb{Q}$ |
$2\in \{2,3,4\} \cap \{1,2,3\}$ | $2\in \{2,3,4\} \cap \{1,2,3\}$ |
$f:A\to B$ | $f:A\to B$ |
$f(x_1)\neq f(x_2)$ | $f(x_1)\neq f(x_2)$ |
$\{a_n\}_{n=1}^{\infty}$ | $\{a_n\}_{n=1}^{\infty}$ |
$(f\circ g)(x)=f(g(x))$ | $(f\circ g)(x)=f(g(x))$ |
$\frac{a}{b}+\frac{c}{d}\neq \frac{a+b}{c+d}$ | $\frac{a}{b}+\frac{c}{d}\neq \frac{a+b}{c+d}$ |
Greek Letters
Greek letters are typeset using \name
: for example, \theta
produces \(\theta\) (as long as you also include the appropriate delimiters). In order to produce a left or right brace, the brace needs to be preceded by a backslash. For example, $\mathbb{N}=\{1,2,3,\ldots\}$ is typeset with $\mathbb{N}=\{1,2,3,\ldots\}$
and notice the use of \{
and \}
, which are needed to obtain the braces for the set.
Display Style
Using $\LaTeX$ allows you to do fancy things like the following:
\begin{align*} \sum_{i=1}^{k+1}i & = \left(\sum_{i=1}^{k}i\right) +(k+1)\\ & = \frac{k(k+1)}{2}+k+1 & (\text{by inductive hypothesis})\\ & = \frac{k(k+1)+2(k+1)}{2}\\ & = \frac{(k+1)(k+2)}{2}\\ & = \frac{(k+1)((k+1)+1)}{2}. \end{align*}
which is typeset using
\begin{align*}
\sum_{i=1}^{k+1}i & = \left(\sum_{i=1}^{k}i\right) +(k+1)\\
& = \frac{k(k+1)}{2}+k+1 & (\text{by inductive hypothesis})\\
& = \frac{k(k+1)+2(k+1)}{2}\\
& = \frac{(k+1)(k+2)}{2}\\
& = \frac{(k+1)((k+1)+1)}{2}.
\end{align*}
Note: In Moodle, you need to frame the above code with the display delimiters: \[
and \]
.
Quotation Marks
To correctly typeset double quotation marks in a full-fledged $\LaTeX$ document (not Moodle), you should use the following syntax; otherwise, the left pair of quotes will be backwards.
``stuff you are quoting"
To obtain the symbols on the left, look for the key on your keyboard in the upper left corner that also has the tilde (~) on it. You'll need to hit this key twice. Using incorrect quotation marks is one of the most common mistakes that I see in documents written using $\LaTeX$.
More Information
Memorizing or looking up \(LaTeX\) commands can difficult for beginners. Thankfully, there are a couple of really neat web-based tools available to help out.
- Web Equation by VisionObjects: Allows you to draw complicated mathematical expressions and it will return to you the appropriate \(LaTeX\) code.
- Detexify: Similar to above, but you can only draw one symbol at a time.
Below is a more comprehensive list of symbols taken from here.
For a list of some of the more common \(\LaTeX\) symbols, see here. If you want to see a really, really, really long list of symbols, go here.
Lastly, you may find the following resources useful:
Note: The rest of this page only applies to using a full-blown $\LaTeX$ editor and does not apply to typesetting in Moodle.
Using a LaTeX Editor
Writing a $\LaTeX$ document is much more complicated than just starting to write. There are a whole host of things that you need to put at the top of your document and this can be rather intimidating at first. The big picture is that the content of your document comes after the line \begin{document}
. All of the stuff before this line is called the preamble and when you first start learning $\LaTeX$, you should just ignore this stuff. Below, I've included some templates to get you started. In the beginning, don't worry too much about all of the complicated stuff in the preamble.
The .tex file is where you type the content of your file. You won't see the output until you compile it. If you've done everything correctly, the output after compiling will be a PDF. I highly recommend compiling often to see what you've got so far and to make it easier to find your syntax errors if you have any.
When you are typing the content of your document, you will partition your content into various environments. Examples of environments include: theorem, proof, align*, itemize, enumerate
, but there are lots more. Every environment begins with \begin{environment-name}
and ends with \end{environment-name}
. For example, see the example above that uses the align*
environment. As another example, if you wanted to write the statement of the theorem that divides is transitive, you would write:
\begin{theorem}
Let $a,b,c\in \mathbb{Z}$. If $a|b$ and $b|c$, then $a|c$.
\end{theorem}
Note: $\LaTeX$ ignores whitespace. What this means is that extra spaces and carriage returns (i.e., hitting the space bar or return/enter key repeatedly) have no impact on the output of the .tex document. You can adjust vertical spacing using commands like: \newline, \bigskip, \medskip, \smallskip, \vspace{1cm}, \vfill
. If you experiment with these commands, you'll be able to see what impact they have.
LaTeX Template for Homework
You can find a $\LaTeX$ template for typing up your homework here. Either download the .tex file or copy the contents of the gist. Alternatively, you can find the template in my public ScribTeX folder. In this directory you will also find a help file for using $\LaTeX$ with ScribTeX. You can download the entire directory (and then if you are using ScribTeX, upload the files you are interested in using) or you can copy the content of the file and paste it into a new .tex file.
Using LaTeX via ScribTeX
ScribTeX is a free online $\LaTeX$ editor and has everything you need to use $\LaTeX$. To get started, go to ScribTeX and create a free account. After logging in, you will be taken to your dashboard, which shows your current projects. Create a new project and name it whatever you'd like. The free version of ScribTeX allows you to make up to 3 projects and each project may have as many files as you want in it. If you are using ScribTeX to write up your homework, having one project called "Homework" should work. In that project, you can store each of your write-ups. However, if you plan to share your project with another ScribTeX user, I suggest appending your last name to the title of the project. For example: "Homework (Ernst)".
Once you have created a project, you can create new files by clicking the "New File" link within your project. You should append .tex to each of your filenames, which is the file extension for $\LaTeX$/$\TeX$ files (similar to .doc for MS Word files). You should probably avoid spaces in your filenames.
I recommend uploading the two templates that I have provided in my public ScribTeX folder. It might be a good idea to upload two copies of each: one that you leave as a template and another that you modify. Once you have done some editing of your .tex file, click "Compile" in the upper lefthand corner. If you've not made any syntax errors, you should obtain a PDF file as output, which you can then download. If you make some errors, ScribTeX will either compile what it thinks you mean and tell you there are errors (look in the upper righthand corner of the screen with the PDF) or it will fail to compile, in which case, it will attempt to tell you what the errors are. In the latter case, you'll have to go figure out what they are and fix them. As I said above, I highly recommend compiling often to see what you've got so far and to make it easier to find your syntax errors if you have any.
Installing LaTeX on Your Own Computer
Installing on a Mac
If you have a Mac, installing and using $\LaTeX$ is easy. All you need to do is go to
and download the latest version of the MacTeX distribution (filename should be MacTeX.mpkg.zip). Once you have downloaded the package, double-click the installer (if it doesn't run automatically). If you follow the instructions during the installation, you will be provided with the $\LaTeX$ "backend" (which you can safely ignore) and the "frontend" editor TeXShop (which will be located in a folder called TeX in your Applications folder). TeXShop will be the default application for editing any file with a .tex extension. To get started, I suggest opening up and playing with the homework template from my public ScribTeX folder. After editing the file, click "Typeset" and if you don't have any errors, TeXShop will render the corresponding PDF. I recommend clicking "Trash Aux Files" in the Console window after you are down editing. If you have questions about using TeXShop on a Mac, please ask!
Installing on a PC
To get up and running with $\LaTeX$ on a computer running Windows, you need to install two things. First, install the MiKTeX "backend":
Click the "download" link at the top of the list under MiKTeX Releases and following the instructions. After installing, search for the application TeXWorks, which you will use to actually type \(\LaTeX\) documents.
Installing on a computer running Linux
Most Linux distributions (e.g., Ubuntu, Debian, Fedora, etc.) use a package manager to install and update software. (Don't use a web browser to look for LaTeX online. Your computer already knows where to go online to find LaTeX and how to install it.) These instructions assume you are using Ubuntu, but similar actions will work on any Linux distro with a modern package management system. Using your package manager ("Ubuntu Software Center" or similar in your applications menu) and assuming you have an internet connection, you need to search for and install two things:
- A LaTeX backend: For the most basic install, search for and install "texlive-base". For a more comprehensive install, search for an install "texlive-full".
- A LaTeX editor: Search for and install "Kile". Kile is the editor of choice for many Linux users writing LaTeX.
After Ubuntu installs these, you should find Kile in your applications menu and it should be capable of calling the various LaTeX programs automatically.
Credits
This page is an adaptation of Andy Schultz's Quick LaTeX Guide and Elisha Peterson's LaTeX Help. Thanks to Jason B. Hill for providing instructions for installing $\LaTeX$ on a computer running Linux. The mathematical symbols on this page were typeset using MathJax.