Chapter 3 Introduction to LaTeX

This is a brief introduction to LaTeX, with a heavy focus on how you can understand and start using LaTeX. For a more detailed introduction, see the intro offered by Overleaf. For history and advantages of using LaTeX, see here. I heavily lifted informaiton from these two documents. I emphasize one advantage: to produce beautiful and reliable documents. In short, you should write academic papers using LaTeX.

3.1 General Structure

Every LaTeX document consist of the following general form. Unlike R, comments are added by the % sign – the % and everything following it (till the end of the paragraph) will be ignored.

prologue % usually empty
\documentclass[options-list]{document-class}
preamble 
\begin{document} 
document-body 
\end{document} 

Commands start with a backslash \. The \documentclass command with the argument in the curly braces telling LaTeX what kind of document we are creating. For instance, \documentclass{article} tells it to create an article. The square brackets further specify the details. For instance, \documentclass[11pt]{article} tells LaTeX to make the font size 11pt.

preamble includes commands that define information about and influence the style of the document. It can also include \usepackage commands that load add-on packages to be used in the document.

3.2 Commands and Environments

A command typically takes one of the formats:

  • A backslash followed by a single non-alphanumeric character.
    • Used to specify special characters and line breaks (e.g., \%).
  • A backslash followed by a name consisting of only letters (e.g., \noindent).
  • \commandname[optional-args]{mandatory-args} Must provide mandatory arguments (within the curly braces); optional arguments (specified within the square brackets) not always defined (e.g., \includegraphics[0.5]{file.pdf}).

An enviroment is defined with a \begin{env} and \end{env} command. It can be thought of as a “container”.

3.3 Preamble

The preamble often includes the following command.

  • \title{document's title}
  • \author{your name}
  • \date. You can can suppress the printing of any date, print today’s date, or print a specified date depending on its format.

Additionally, you may also include

  • \pagestyle{style}, which specifies the content and format of the header and footer on all pages of the document.
  • other \usepackage[options]{package-name} commands.

3.4 Document Body

In addition to the text you write, here are some commands you typically include.

  • \maketitle, which produces the title of your document.
    • must be preceded by \title and \author commands.
    • typically placed directly below the \begin{document} command.
  • \tableofcontents, which creates a table of contents.
    • typically placed directly below the \maketitle command.
    • may need to be compiled twice.
  • \section[entry]{heading} (\subsection and \subsubsection) to start and name new sections.
    • entry argument can be used to specify a shorter heading.
  • paragraphs are ended by one or more completely blank lines (equivalent to the \par command).
    • Indention by default. You can suppress indention by the \noindent command.
  • \footnote[i]{text} produces footnotes.
    • use the optional argument i to specify the footnote number.
  • \cite{cite_key} helps you cite a given document.

Here are some enviroment you typically encounter.

  • The itemize and enumberate environments, which generates bulleted and numbered lists respectively.
    • use \item to indicate each entry.
  • The tabular environment, which generates a table.
    • use \caption to add a caption.
  • The figure environment, which inserts an image.
    • use the \includegraphics[options]{file} command.

Here are some additional commands.

  • Cross reference for tables, figures, sections, and more.
    • use \label{marker} next to the command or environment you wish to refer to.
    • use \ref{marker} to produce the reference.
  • Special symbols # $ % & { } _ ~ can be used by following the backslash.
    • use $\backslash$ for the backslash itself.
    • use back-tick ``` to begin a quotation.
    • use apostrophe ' to end it.
  • Change font.
    • use \textit{text} to italicize, \textbf{text} to bold, and \textsc{text} to to produce SMALL CAPS.
    • use \tiny, \large, \Hugh, and others to change font size.

3.5 Some Examples

To write mathematical equations, you can invoke the equation environment. For instance,

\begin{equation}
\sum_{k=1}^{n} \frac{1}{2^k}
\end{equation}

gives you \(\sum_{k=1}^{n} \frac{1}{2^k}\).

To write a table, you can invoke the tabular environment. For instance,

\begin{tabular}{|l|r|r|} \hline
Item & Qty & Unit \$ \\\hline
Widget & 1 & 10 \\
Gadget & 2 & 11 \\\hline
\end{tabular}

gives you a nice table (not shown here).

Now that we have some experience with LaTeX, let’s try out some more examples.

  • Download and open the tex file from Tim’s website. Try compiling the file. See if you understand all the code.
  • Finish up the intro offered by Overleaf. Note that this is only part 1 of the Overleaf introduction. Somewhere down the line you should also read part 2, which talks about citation and bibliography. You may also be interested in the beamer package which helps with presentation and the TikZ package which helps you draw figures (including game trees).

3.6 Additional Information

For additional commands, environments, and packages, you can also google. You can also consult the wiki for LaTeX. Websites such as CrossValidated and stackoverflow will be your friends for the years to come where you can ask questions and search for answers. These two sites are also great places for statistic and programming questions. Finally, google will typically leads you to these sites.