›INDEX
Last Updated:

Latex

Latex is a software system for document preparation. It's a form of creating structured documents without using processors like Microsoft Word but rather just plain text. Having configuration in plain text makes it really modular and script-able. In my opinion, it also makes the document style and format a lot more precise.

Installation For Arch Linux

We can use a software system called texlive to compile latex documents.

  • For Arch-Linux: pacman -S texlive-most
  • For Ubuntu based: apt install textlive-full

You can just look up the specific way to install texlive for your system.

Testing The Installation

Let's create a test document that we can compile to test our installation.

test.tex

\documentclass{article}

\begin{document}
    Hello World
\end{document}

Once we have saved that text file, we can compile it to a pdf using the following command:

pdflatex test

This should output a couple of files, including test.pdf.

Introduction

Hello World

\documentclass{article}

\begin{document}
    Hello World
\end{document}
  • documentclass{article} declares the document type known as its class, which controls the overall appearance of the document.
  • begin{document} and end{document} holds the body of the document.

Content before the begin{document} is called the preamble which acts as the document's "setup" section.

Including Author And Other Information

We add more lines of "preamble" to declare things like author, date, and title of the document.

\documentclass[12pt, letterpaper]{article}

\being{documnet}

\title {My Latex Document}
\author{Suchith Sridhar}
\date{January 2023}

\end{document}

This only declares this information in the document. We use the \maketitle command within the body of the document to typeset the title, author, and date.

Comments

Latex is a form of "program code" that's just specialized to document typesetting. It may be helpful to have comments within the document to allow some information to the .tex document reader.

We use the % symbol at the beginning of the line to declare the line as a comment.

Example:

\begin{document}
    % This line here is a comment and will not be 
\end{document}

Sections

All text should be divided into sections, sub-sections, and further. The following sectioning commands are available for the article class.

  • \section{...}
  • \subsection{...}
  • \subsubsection{...}
  • \paragraph{...}
  • \subparagraph{...}

With the report and book classes we also have \chapter{...}

\section{Introduction}

This is the introduction.

\section{Methods}

\subsection{Stage 1}

The first part of the methods.

Labelling

You can label any of the sectioning commands, any equations, figures etc so that they can be referred to in the other parts of the document. Label a section with the \label{labelname} command. Then use \ref{labelname} or \pageref{labelname}, when you want to refer to the section or page number of the label.

Example:

\section{Introduction}

\subsection{Labelling}
\label{seclab}

\subsection{References}
We use references such as: \ref{seclab} on page \pageref{seclab}.

Note, it's common practice to use \label{eq: name} and \label{fig: name} and such for equations, figures, and tables to make it easier to understand.

Table of Contents

If you use sectioning commands, you can use \tableofcontents where you want the table of contents to appear in your document.

White-space

Here are some common white-space adding commands that may be useful when typesetting in tex.

  • \newpage: Insert a page break.
  • \: Line break.
  • \vspace{...}: vertical space, ... can be 1em or 12pt etc.

Typesetting Text

There are latex commands for variety of font effects:

\textit{words in italics}
\textsl{words slanted}
\textsc{words in smallcaps}
\textbf{words in bold}
\texttt{words in teletype}
\textsf{sans serif words}
\textrm{roman words}
\underline{underlined words}

Colored Text

To have colored text in documents, we need to use a package. \usepackage{color} knows the colors black, red, green, blue, cyan, magenta, yellow, and white.

{\color{color_name}text}

Font Sizes

{\tiny tiny words} tiny words
{\scriptsize scriptsize words} scriptsize words
{\footnotesize footnotesize words} footnotesize words
{\small small words} small words
{\normalsize normalsize words} normalsize words
{\large large words} large words
{\Large Large words} Large words
{\LARGE LARGE words} LARGE words
{\huge huge words}

Lists

The enumerate and itemize environments can be used to create lists. Enumerate generates a numbered list where as itemize generates a bulleted list. The command \item is used to indicate a new item in the list.

\begin{enumerate}
\item First thing
\item Second thing
\end{enumerate}

\begin{itemize}
\item First
\item Second
\end{itemize}

You can specify the bullet for a single item using square brackets.

\begin{itemize}
\item[+] First
\item[-] Second
\item[Word] A world for a bullet?
\end{itemize}

Math In Latex

Before we can start writing math in latex we'll need to include some preamble to let it know that we're going to be using some math expressions.

\documentclass{foo}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\begin{document}
\end{document}

Ways to Insert Math

There are two ways to insert math into Latex documents.

  • Inline math: short, not too long, simple.
  • Display mode: can be tall, complex, is a block of it's own.

Example of inline math:

We solve \( x^2 + 2 \) over the complex numbers \( \mathbb{C} \).

Example of display mode:

My favorite funciton is not

\[
\zeta(s) = \sum_{n=1}^{\infty}n^{-s}
\]

Equations

Equations are inserted using the equation environment.

\begin{equation}
1 + 2 = 3
\end{equation}

A group of equations can be done using the eqnarray environment.

\begin{eqnarray}
a & = & b + c \
  & = & y - z
\end{eqnarray}

Note: both equation and eqnarray have numbers and you can choose to not number them by appending a * at the end of the environment name, example: equation*.

Note: You can use \label for any line in the equations to create reference to it in some further text.

Enjoy the notes on this website? Consider supporting me in this adventure in you preferred way: Support me.