LaTeX is the standard tool for scientific writing and typesetting. Here is a sample LaTex file. LaTeX is a markup language, which means that you provide text along with commands to typeset or markup that text. You then need to compile a LaTeX document.
Compiling LaTeX
The easiest and most direct way to compile is via pdflatex. Here’s an example:
pdflatex LearningLaTeX.tex
This will either produce a pdf document you can read with a standard pdf reader such as Acroread, or will print out error(s) encountered during the LaTeX compilation process.
Working with LaTeX remotely.
If you are working with LaTeX remotely, you might not have LaTeX installed on your local machine. In this case, you have a couple of options:
-
Edit/Compile your LaTeX file on lab machines. To this, you’ll need to ssh into a lab machine, and edit/compile your LaTeX file from there. Then, you can use scp to copy your compiled pdf to a local machine to read it.
-
Use an online LaTeX editor such as Overleaf. In past years, several students have used overleaf to write their LaTeX. It is convenient for writing partered assignments. Warning: Overleaf tends to ignore compilation errors and give you the best pdf it can render. Before submitting a LaTeX file, make sure you can compile it using pdflatex and it looks the way you’d like.
-
Install pdflatex on your home machine.
The basic structure of a LaTeX file
It is likely that you will modify an existing LaTeX template file (e.g. this template) rather than starting from scratch. However, if you do start from scratch, the following snippet of LaTeX illustrates the minimal code needed to get started.
\documentclass{article}
\usepackage{amsmath} % Math notation from the American Mathematical Society.
\usepackage{amssymb} % Typographical symbols from the same.
\begin{document}
Hello!
\end{document}
Brief explanations of each line lie below:
-
The line
\documentclass{article}
tells LaTeX you want to write an "article" document. LaTeX documents start with this line. -
The next few lines add LaTeX packages, which are similar in spirit to
#include
lines in C++ orimport
in Python. -
\begin{document}
and\end{document}
specify where the content of your document starts and stops.
Formatting
LaTeX has several formatting commands that make your file look nicer. A few are listed below:
-
\textit{this is italicized.}
renders 'this text' in italic. Here is what gets produced \(\textit{this is italicized.}\) -
\textbf{this is boldface.}
gets rendered as \(\textbf{this is boldface.}\)
LaTeX has environments for bullet lists and numbered lists.
-
The itemize environment gives unordered bullet-lists.
Here is an unordered list.
\begin{itemize}
\item Your first item is here.
\item This is your second item.
\item This is the third item.
\end{itemize}
Here is the compiled LaTeX.
Here is an ordered list.
\begin{enumerate}
\item Item One.
\item Item Two.
\item Item Three.
\end{enumerate}
Here is the compiled LaTeX.
Math
One of the real strengths of LaTeX is its ability to easily typeset mathematical notation. To render mathematics in LaTeX, enclose the math in dollar signs e.g.
The quadratic equation is $ax^2 + bx + c = 0.$
Which gets rendered as: \(\text{The quadratic equation is }ax^2 + bx +c.\)
Sometimes, it’s nicer to put the math on its own line, cenetered in the page. Do this using double dollar signs:
The quadratic equation lies below: $$ax^2 + bx + c=0\ .$$
Here is the compiled LaTeX.
The align* Environment
If your LaTeX math runs across multiple lines of text, LaTeX provides an elegant way of typesetting this nicely called the align\* environment. Here is some sample LaTeX code:
\begin{align*}
(n+1)(n-1) &= n^2 + n - n -1 \\
&= n^2-1
\end{align*}
which gets rendered as:
\(\begin{align*} (n+1)(n-1) &= n^2 + n - n -1 \\ &= n^2-1\end{align*}\)
Make sure to put a double backslash '\\' to denote the end of each line of your math equations. (no double-backslash is needed after the last line). The ampersand '&' is a control character that specifies vertical alignment. When this LaTeX is compiled, it will line up each line where the ampersands are. In this example, the equal sign in the second line of math will line up immediately below the equal sign in the first line.
Subscripts and Superscripts
In math mode, it is common to use subscripts and superscripts. You can do this in LaTeX using '_' and '^'. For example:
$a_0 = x^2 + 4$
gets rendered as \(a_0 = x^2 + 4\)
Summations
If you want to write summations, use the \sum
command. For example,
$\sum_{i=1}^n i = \frac{n(n+1)}{2}.$
is rendered as \(\sum_{i=1}^n i = \frac{n(n+1)}{2}.\)
Including Images
To include an image, use the graphicsx
package and the
\includegraphics
command.
...
\usepackage{graphicsx}
...
\includegraphics{bunny.jpg}
...