LaTex, pronounced “lay-tech”, is a typesetting software particularly suitable for scientific writing. Some of its key features are:
\
.We will be using OverLeaf, that offers an easily accessible interface to LaTeX. If you would rather install software on your computer to work with LaTeX, contact me and we’ll see what we can arrange.
We will work through many of the things you will need in this document. There are many online resources as well. The documents at this page that don’t refer specifically to ShareLaTeX features are well organized and relevant to us. And you should always feel free to ask me if you are not sure how to do something.
In the blank document, add the following:
\documentclass[12pt]{article}
\usepackage[vmargin=0.5in, hmargin=0.5in]{geometry}
\usepackage[T1]{fontenc}
\usepackage{stix}
\usepackage{paralist}
\usepackage{attrib}
\usepackage{amsmath}
\usepackage{amsthm}
\title{Place your title here}
\author{Put your name here}
\date{\today}
\begin{document}
\maketitle
Some text here
\end{document}
If all has worked well, you should see on the right-side a rendering of your document, showing the title, the name and some text. Everything else is invisible but gives instructions to the system for various things. We will discuss them in a minute.
The content between the lines \begin{document}
and \end{document}
is the “main document”. This is where you will be putting most of your work. The stuff that comes earlier is the preamble.
The first line in the document is always a \documentclass
line. In this case it tells the system that it should use the format rules for an article, which specifies title size, author and date placement, and other stylistic choices. In this case we also tell it that we want the base font size to be 12 points. Unfortunately you do not have too many options for the font size 12 points is the largest that it can go.
Then we have a couple of \usepackage
commands that load packages that do useful things. The first one is the “geometry” package, which allows you to control the margins of the page. Try to change the numbers to see the effect. “hmargin” is for horizontal margins, “vmargin” controls vertical margins. You can use different measuring units rather than inches, for instance 1cm
will create 1 centimeter spacing. All this information within the square brackets is called the “package options”.
Notice a bit further down a \usepackage{paralist}
. This allows us to customize lists later on. And \usepackage{attrib}
allows attributions in quotes, if you ever need those.
The next two lines set up an appropriate font, in this case a font called Stix. I encourage you not to do this right now, but you can find a long list of available fonts as well as the instructions for how to enable them here. Aim for the section that says “Fonts with math support”. You can only have one font choice per document, without a fair bit of extra work.
You will find that LaTeX makes some things hard. For instance, if you want different parts of your text to have different fonts, it is not easy to do. LaTeX aims to provide you uniform styles, and gives you control over setting those uniform styles, but doesn’t allow you to deviate a lot. The main stylistic choices you have are:
\textrm{normal text here}
in situations where normally typing text would not treat it as normal.\emph{put the text you want italic here}
. It will also automatically enable italic text in certain settings like theorem statements, depending on the document class setting. In those instances, the above command will make the text in it normal, i.e. it always makes it “stand out from its surrounding text”. You can also use \textit{italic text here}
.\textbf{put the text you want bold here}
.After the font specifications there are a couple of lines that define information about the document, in this case a title, the author, and a date specification to automatically pick up today’s date. You could just instead write out a specific date as you want it to appear, instead of \today
.
There are many more things we can put in the preamble. But for now this will suffice.
The main document is contained within the block created by the \begin{document}
and \end{document}
. Everything you type there is going to appear as text on the right, but there are some important rules to keep in mind:
\{
or \$
or \\
.Newlines are ignored, unless there are at least 2 of them back to back. So in order to start a new paragraph you have to hit “return” twice. Like so:
A paragraph here
A new paragraph here
There are two ways to enter “math mode”. We will also be discussing theses shortly. All your mathematics should be done in this mode.
There are special commands to use when you want to start a new section, subsection etc. For articles, the options we have are section, subsection, subsubsection, paragraph and subparagraph. Each of these has a corresponding command, with a backslash in front, and then in braces you put the name of the section. So here is some example text, type (or copy-paste) it in and see how it looks:
\section{This is a section heading}
Stuff about the first section in here. The settings for how these headings appear are set globally, and you should not try to change them.
\subsection{A subsection within the first section}
Stuff about the subsection. Notice that the subsection is numbered within the section.
\subsection*{An unnumbered subsection}
You can disable the numbering on any of these elements by putting the star before the curly brace like in the line above.
\subsubsection{A sub-subsection}
Subsubsection text.
\paragraph{A paragraph}
Some paragraph text. Notice that paragraphs and subparagraphs do not follow the numbering.
"Paragraph" here just means a part of the text identified as a unit smaller than a subsubsection. It does not need to be a literal paragraph. But it is convenient to use for paragraphs that have a "title".
\subparagraph{A subparagraph}
Subparagraph text.
You really do not need to use all those 5 different levels. But they are available.
There are three kinds of lists you can make in LaTeX: Numbered (enumerated) lists, itemized (“bullet”) lists and “description lists”. Here’s some examples, paste them in the text to see how they would look:
Lists start and end with a begin-end block:
\begin{enumerate}
\item This is the first item in the list. Notice that the numbering started automatically at 1. You can customize that if you need to, but you should not have to. We will now start a sublist within this first item: We indented it a bit to remind us of the fact that it's a sublist, but LaTeX won't care either way.
\begin{enumerate}
\item Here's a subitem.
\item Another subitem.
\end{enumerate}
We will now make another sublist that is formatted slightly differently. Notice the i and dot, telling it to use latin numerals and a dot instead of a parenthesis:
\begin{enumerate}[i.]
\item First!
\item Second!
\item[Hey!] You can interrupt the numbering by inserting whatever you want in brackets, and it will replace the number. But use this sparringly.
\end{enumerate}
\item Here's a second item on the main list.
\begin{itemize}
\item And here's a bullet list.
\begin{itemize}
\item And one inside it.
\end{itemize}
\item A second item.
\end{itemize}
You can also make lists with less space between the items:
\begin{compactenum}
\item See.
\item We're close!
\item you can also try replacing "compactenum" at the begin/end with "asparaenum" and "inparaenum" and see how they look like.
\item You also have the choices of "compactitem", "asparaitem", "inparaitem".
\end{compactenum}
\end{enumerate}
Description lists expect each item to have a "term" and a "description" like so:
\begin{description}
\item[A term] The term's description.
\item[Another] They are formatted this way.
\end{description}
You can also try "compactdesc", "asparadesc" and "inparadesc".
If you want to suggest a “quote”, there are two possible “environments”, quote and quotation. Paste the following in to see their difference:
Quote:
\begin{quote}
A long text here to make sure we move to a new line. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line.
\attrib{The author}
Starting a new paragraph. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line.
\end{quote}
Quotation:
\begin{quotation}
A long text here to make sure we move to a new line. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line.
\attrib{The author}
Starting a new paragraph. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line. A long text here to make sure we move to a new line.
\end{quotation}
Here are some other features when writing “normal” text. Just paste them in and see the effect:
Use two backticks ``to start a left double-quote, and two single quotes to close it''. This will insert better looking quotes than if you use the "normal double-quote" character. Do the same for `single quotes'.
Using consecutive dashes has the effect of producing what is known as an "en-dash" (--) or an "em-dash" (---).
There are a number of provided environments for creating standard math document sections like a theorem statement, a proof and so on. Most of these were loaded with the “amsthm” package that was loaded at the preamble. Here’s some example uses. You can read a lot more about what this package provides at its documentation page, but we’ll discuss the main things you’ll need in these notes, and the next section which focuses on writing math.
You should first add the following lines to the preamble, below the \usepackage{amsthm}
line:
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem*{note}{Note}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
The lines above created 5 new environments:
theorem
, which prints “Theorem” and is numbered within sections.lemma
and corollary
, which both follow the theorem’s numbering.remark
and note
, both unnumbered.Here’s an example of using these. Paste it in the main document section to see how it looks. You also will see how we can add a “proof” with the special nice box at the end.
\begin{theorem}
Here's the theorem's statement. Notice the numbering, which is based on the section number.
\end{theorem}
\begin{proof}
Here is where we would write the proof.
This could take many pages. We will learn how to put math here in the next section.
\end{proof}
\begin{corollary}
See how the numbering of this corollary follows the theorem's numbering.
\end{corollary}
\begin{lemma}
Lemmas also follow the numbering from theorem.
\end{lemma}
\begin{proof}
And here's the lemma's proof.
\end{proof}
Now let's add a remark:
\begin{remark}
Here is the remark's text. Notice how the remarks are formatted differently than the previous items. That is because we had a line about a different "theoremstyle" in the preamble where we defined the remark environment.
\end{remark}
\begin{definition}
And here is a definition. Notice that its style is different from both of the previous two style. And it follows an independent numbering from the theorems lemmas etc, but still below sections.
\end{definition}
Now we discuss how to write mathematics in LaTeX, one of its main strengths. There are two different math modes:
\(
and close it by \)
. You can also use one dollar sign to open and close, but you should use the backslashed parentheses instead.\[
and \]
. There are also other ways to create more complicated math environments, as well as ways to number the equations for later reference.A lot of things are different in either math mode:
^
to indicate superscripts. If you want to put more than one character as subscript or superscript, enclose it in curly braces. In general curly braces group together things you want to treat as “one”.\textrm{...}
.Here’s some sample text. Paste it in to see how it looks:
Here's an inline equation: \( e^{x + \frac{2}{x}} \).
Here's some display math:
\[
\cos x + i \sin x
\]
You can create numbered equations by using the equation environment. Also notice the use of left and right commands around the parentheses, which makes them enlarge to the correct size to match their content:
\begin{equation}\label{eqn:important}
\sum_{i=1}^n \cos\left(x + \frac{1}{x^2+1}\right) > \prod_{i}^{i\leq 5} a_i b_i
\end{equation}
We also created a "label". What that does is store the number that the equation has. We can then automatically insert it in the text by saying something like: equation~\eqref{eqn:important} is useful or just~\ref{eqn:important}. if you don't want the parentheses. You can do the same thing on theorems, for example we can refer to theorem~\ref{thm:coolTheorem} below:
\begin{theorem}\label{thm:coolTheorem}
A cool theorem whose number we can reference!
\end{theorem}
There is a special environment for aligned equations. The ampersand indicates the place where things should align vertically (often the equals sign), while the double backslash at the end of a line indicates that a new line should start:
\begin{align*}
y &= x + 3\\
&= 5 + 4 = 2
\end{align*}
There are lots of other possibilities. Just ask if you want to do something and you’re not quite sure how to do it!
Paste them in and see how they look:
$\mathbb{C}$
$\mathbb{N}$
$\exists x \in A$
$\forall x\, x > 3 \implies x > 2$
$x \mapsto f(x)$
$\alpha \beta \gamma \Gamma$
Can I get a table of contents?
Yes! Just add the line \tableofcontents
right after the \maketitle
line. It will automatically update itself as you add sections and subsections.
How do I do lines over characters (conjugates)?
For a single character, do \bar z
. For a longer line, do \overline{...}
How do I include graphics I have made in some other application?
See this link: https://www.overleaf.com/help/111-how-do-i-insert-an-image-into-my-document#.VrOBGWQrJcw. The important parts are:\usepackage{graphicx}
in the preamble if it’s not already there\includegraphics[width=\textwidth]{YOUR-FILE-NAME-HERE}
where you want the file to be inserted. You can also use 0.8\textwidth
if you want it to take up 80% of the text’s width, or you can insert a precise measure like 2.4in
.