JMU UUG LaTeX Tutorial
Introduction
BEFORE WE START: Get an Overleaf account.
Overview: The TeX typesetting system originated with Don Knuth in 1970s, prompted by his work on “The Art of Computer Programming.” It first ran on a PDP-10 in 1978. TeX uses a versioning system w/ increasing digits of π; lastest is 3.14159265. It was extended to LaTeX by Leslie Lamport (@ SRI International) in 1980s, and is now a full document preparation system. The latest version is LaTeX 2e. LaTeX is widely used in CS, Math, Engineering, and other scientific fields.
Introduce concepts:
- Compiled typesetting (composing documents like C/Java programs)
- Document description language (markup, like HTML)
- Philosophy of separate content and form/presentation (like CSS)
Note: LaTeX is pronounced “lah-tech” or “lay-tech”, NOT “lay-techs”!
Document organization
- First thing:
\documentclass{article|IEEEtran|proc|report|book|beamer}
- For smaller margins:
\usepackage[margin=1in]{geometry}
- For UTF-8 support:
\usepackage[utf8]{inputenc}
- For smaller margins:
- Document info:
\title
,\author
,\date
,\maketitle
- Page numbers:
\pagenumbering{roman}
,\thispagestyle{empty|plain}
,\pagestyle{empty|plain}
- Organization:
\section
,\subsection
,\subsubsection
- Others:
\tableofcontents
,\label
,~\ref
- Use asterisk to toggle numbering
- Others:
- Comments w/
%
Formatting
- Lists:
\begin{enumerate|itemize}
,\item
- Common font/color formatting
\textbf
,\textit
,\texttt
,\underline
, quotes,--
,---
- Shorter forms:
{\bf }
,{\it }
,{\tt }
\usepackage{xcolor}
,\textcolor{color}{text}
\begin{tiny|small|large|huge}
\begin{verbatim}
,\verb!
- International formatting: UTF-8 or
\’
,\”
,\~
, etc.
- Footnotes:
\footnote
- Images:
\includegraphics{file.png}
- Requires
\usepackage{graphicx}
- Options:
[scale=0.5]
,[width=1in]
,\begin{center}
- Requires
- Floating figures:
\figure
- Options:
\caption
,\label
(needs to go at the end),~\ref
- Works for verbatims or graphics, too
- Options:
- Tables:
\tabular
,\hline
,[l|c|r]
,\multicolumn{n}{cols}{text}
Mathematics
- Math mode:
\begin{equation}
,$
,$$
- Sub/superscript, common operators (
\cdot
,\leq
,\approx
,\times
,\pm
) - Greek letters (e.g.,
\omega
,\Omega
) - Common functions:
\log
,\sin
,\cos
,\tan
,\min
,\max
- More complex operators:
\frac{}{}
,\sqrt[]{}
,\sum
,\prod
,\int
- Delimiters:
\left([{<
,\lfloor
,\lceil
- Logic symbols:
\in
,\subset
,\forall
,\exists
,\rightarrow
- Spacing:
\;
\:
\,
\!
- Fun:
\flat
,\sharp
,\clubsuit
,\heartsuit
,\pitchfork
Bibliography
- Special BibTeX file format (
.bib
) - Download references from ACM Digital Library and/or IEEE Xplore
- Integrates with Zotero
\bibliographystyle{plain}
,\bibliography{fname}
~\cite{key}
Large documents
- Custom
.sty
files and Overleaf templates - Multiple files:
\include
- Importance of unique labels & bibliography management
- Build frameworks (e.g., Makefiles) – need to rebuild multiple times!
- Latexmk and preview apps
Macros
- Declaration:
\def\name{texthere}
- Examples:
\def\topK{\textsf{\textbf{topK}}}
\def\red#1{\textcolor{red}{#1}}
Fun fact: LaTeX is Turing-complete!
Useful Extensions
- AMS (American Mathematical Society) packages (docs)
\usepackage{amsmath, amssym}
\begin{align*}
,\noindent
- Theorems, lemmas, etc. (Overleaf guide)
- Code listings (docs)
\usepackage{listings}
\lstset{language=C|C++|Java|Python|LaTeX}
(or leave out for pseudocode)\begin{lstlisting}
- Algorithm packages
- Overleaf guide
- Wikibooks guide
\usepackage{algorithmicx,algpseudocode}
\begin{algorithmic}
\State
w/ math mode (\gets
for assignment)\If{cond}
,\Else
,\ElsIf
,\EndIf
\For{cond}
,\ForAll{cond}
,\EndFor
\While{cond}
,\EndWhile
\Function{name}{params}
,\EndFunction
,\Return
,\Call
- Semantics/proof rules (docs)
\usepackage{semantic}
\inference[name]{premise(s)}{conclusion}
->
,=>
,|-
- Recursive nesting for proof trees
- Beamer (docs)
\documentclass{beamer}
\begin{frame}
\frametitle
- Sections (same as usual, now with visual indicators)
- TikZ (docs)
- Overleaf guide
\begin{tikzpicture}
(x1,y1) -- (x2,y2)
\draw
,\draw[->]
,\filldraw
\node
Common headaches
- Careful with underscores and other symbols
- E.g.:
$
and#
must be escaped
- E.g.:
- Spacing:
\hspace
,\vspace
,\newpage
- Units:
in
,cm
,pt
- Units:
- Table positioning:
[t|h|b|p]
- Finding typos and syntax errors
- Q&A and experimentation
- TeX StackExchange
Local installation
- Windows - use MiKTeX
- Mac OS X - use MacTeX
- Linux Mint -
sudo apt install texlive-latex-base
- IDEs: LyX, TeXnicCenter, TeXShop
- Plugins: AUCTeX (Emacs), TeXlipse (Eclipse), Vim-LaTeX (Vim)
References
- Overleaf tutorial
- LaTeX Wikibook
- TEXbook
- Quick-reference cards:
Diversions
- Computer Modern Unicode font (choose otf)
- Lilypond - LaTeX-like language for musical notation
- LaTeX math jokes
- Coffee stains and the Simpsons