LaTeX

LaTeX: A Document Preparation System

  • Use commands to indicate document layout
  • Not WYSIWYG: Write marked-up text into a .tex file
  • pdflatex converts LaTeX to a .pdf file
  • You can make papers and presentations with it
  • It is particularly good at formatting and displaying math

A Simple Example

\documentclass{article}

\begin{document}
Hello, \LaTeX{}!
\end{document}

Final Product

Document Classes

Document Classes

  • Article: For writing papers, assignments, etc.
  • Report: Like article, but for things that are multiple chapters long.
  • Book: For formatting actual books.
  • Beamer: For making presentations like this one.

Document Structure Example

\documentclass{article}
\begin{document}
\section{Introduction}

\section{Methodology}
\subsection{A Perpetual Energy Source}
\subsection{A Radio Beacon for the Pyramids of Giza}
\subsection{Plans for First Contact}

\section{Results}
\subsection{Physics Dislikes Me}
\subsubsection{Physicists don't want the truth}
\subsubsection{This foil is perfectly comfortable, thanks}

\section{Conclusion: Perhaps the real aliens are the friends we made along the way}
\end{document}

Final Product

Title Example

\documentclass{article}
\title{Do Lizards Run The World?}
\author{Mike Wisely}
\date{\today}

\begin{document}
\maketitle

\end{document}

Final Product

Text and Formatting

Special Characters

  • # $ % ^ & _ { } ` ~ \ are reserved characters.
  • You can write them using these escapes: \# \$ \% \ˆ{} \& \_ \{ \} \`{}\˜{} \textbackslash{}.
  • % starts a comment that runs until the end of the line.
  • \\ forces a line break.
  • \^ and \~ by default draw above the next letter, so \~n looks like ñ.
  • Opening quotes are written with ` and closing quotes with '.
  • `single quotes' looks like 'single quotes'.
  • ``double quotes'' looks like "double quotes".

Formatting Text

  • Bold: \textbf{your text here}
  • Italic: \textit{italic text here}
  • Underline: \underline{underlined text}
  • Monospaced: \texttt{I am a robot}

Lists

List Example

\documentclass{article}

\begin{document}

\begin{itemize}
        \item Itemize makes a bulleted list.
        \item Every item in the list starts with
                the item command.
        \item You can make multiline items\\
                by putting a linebreak in them.
\end{itemize}

\begin{enumerate}
        \item Enumerate numbers each item.
        \item Otherwise it's exactly the same as itemize.
\end{enumerate}

\end{document}

Final Product

Nested List Example

\documentclass{article}

\begin{document}

\begin{enumerate}
  \item You can also nest lists!
  \item Just start a new itemize or enumerate in a list:
    \begin{enumerate}
      \item Enumerates will change numbering style.
      \item Itemizes will use a different glyph.
    \end{enumerate}
  \item Once you're done, you can keep adding new
    list items to the original list.
\end{enumerate}

\end{document}

Final Product

Example

\documentclass{article}
\usepackage{hyperref}
% Set link colors throughout the document
\hypersetup{colorlinks=false,
    allbordercolors={0 0 0},
    pdfborderstyle={/S/U/W 1}
}

\begin{document}
\href{https://google.com}{Ask The NSA Anything!}

\url{http://www.funroll-loops.info/}

\end{document}

Final Product

Math

Displaying Math

  • You can write math inline by putting it between $ signs. $f(x) = xˆ2$ renders as f(x)=x2.
  • Equations can be placed on their own in an equation environment

    \begin{equation}
        f(x) = x^2
    \end{equation}

Displaying Math

  • Subscripts and superscripts
    • x_b and x^a
    • You can even do both at the same time! x^a_b
  • Existential quantification
    • \forall n \in \{1,2,3,4\}
  • Summations
    • \sum_{i=0}^\infty \frac{1}{3^i} = \frac{3}{2}
  • Fractions and quantities
    • \Big(\frac{1}{3}\Big)^k = \frac{1}{3^k}

Math Symbols and Commands

Figures

Figures

  • The figure environment is used to place images and give them captions.
  • LaTeX will place the figure on the page in a spot it thinks makes sense, usually at the top or the bottom.
  • You must put \usepackage{graphicx} below \documentclass.
  • The \includegraphics command can then be used inside a figure to include png, jpeg, pdf, and eps files.
  • The caption command sets a caption for the figure.

Example

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}[h] % Place `here'
  \caption{4-corner simultaneous 4-day time cube}
  \centering % Center the image

  % width=\textwidth makes the image the width of the text
  \includegraphics[width=\textwidth]{timecube.png}
\end{figure}

\end{document}

Final Product

Tables

Tables

  • As with figure, there is a table environment that lets you make tables with captions.
  • Inside the table environment, you put a tabular environment that actually draws the table.
  • http://truben.no/table/ is a website that will generate tables for you!

Code and Algorithms

Displaying code and algorithms

  • The verbatim environment shows text in a plain, monospaced font.
  • If you want syntax highlighting, Pygments works well.
  • The algorithm environment works like the verbatim environment, but it's for algorithms.
  • There are a few algorithm typesetting packages with different appearances.

Example

\documentclass{article}

\begin{document}

\begin{verbatim}
You can write all sorts of stuff here
\command, $$$ cash money, etc.!

\end{verbatim}

\end{document}

Final Product

Other Bells and Whistles

Other Bells and Whistles

  • You can manage citations with Bibtex.
  • LaTeX wikibook.
  • CTAN has documentation on zillions of neat packages.
  • MiKTeX is a Windows version of LaTeX.
  • TeXworks is a nice editor.
  • Pandoc can convert other document formats to and from LaTeX.