Loading...
Loading...
Comprehensive LaTeX reference for document creation, formatting, mathematics, tables, figures, bibliographies, and compilation. Use when helping users write, edit, debug, or compile LaTeX documents.
npx skill4agent add igbuend/grimbard latex| Concept | Description |
|---|---|
| Preamble | Everything before |
| Document body | Content between |
| Commands | Start with |
| Environments | |
| Packages | Extensions loaded with |
\documentclass[options]{class}| Class | Use case |
|---|---|
| Short documents, papers, assignments |
| Longer documents with chapters |
| Books (front/back matter, chapters) |
| Presentations/slides |
| Formal letters |
| Flexible — replaces article/report/book |
\documentclass[12pt,a4paper,twocolumn,draft]{article}| Option | Values |
|---|---|
| Font size | |
| Paper | |
| Columns | |
| Sides | |
| Draft | |
\documentclass[12pt,a4paper]{article}
% === PREAMBLE ===
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath, amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\title{My Document}
\author{Author Name}
\date{\today}
% === BODY ===
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
Content here.
\end{document}| Command | Result |
|---|---|
| bold |
| italic |
| underlined |
| emphasis (italic, or upright if already italic) |
| |
| SMALL CAPS |
| sans-serif |
\tiny \scriptsize \footnotesize \small \normalsize
\large \Large \LARGE \huge \Huge{\large This text is large.}| Command | Declaration | Family |
|---|---|---|
| | Serif (Roman) |
| | Sans-serif |
| | Monospace |
\begin{center} Centered text. \end{center}
\begin{flushleft} Left-aligned. \end{flushleft}
\begin{flushright} Right-aligned. \end{flushright}\centering\raggedright\raggedleft\vspace{1cm} % vertical space
\hspace{2em} % horizontal space
\vfill % stretch vertical
\hfill % stretch horizontal
\\[0.5cm] % line break with extra space
\setlength{\parskip}{0.5em} % paragraph spacing
\setlength{\parindent}{0pt} % remove paragraph indent
\noindent % suppress indent for one paragraphsetspace\usepackage{setspace}
\onehalfspacing % or \doublespacing, \singlespacing| Character | LaTeX | Character | LaTeX |
|---|---|---|---|
| | | |
| | | |
| | | |
| | | |
| | | |
\part{Part Title} % only in report/book
\chapter{Chapter Title} % only in report/book
\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}
\paragraph{Paragraph}
\paragraphsub{Subparagraph}\section*{}\tableofcontents % requires two compilations
\listoffigures
\listoftables% Bulleted
\begin{itemize}
\item First item
\item Second item
\end{itemize}
% Numbered
\begin{enumerate}
\item First
\item Second
\end{enumerate}
% Labeled
\begin{description}
\item[Term] Definition here.
\end{description}enumitem\usepackage{enumitem}
\begin{enumerate}[label=(\alph*), start=1]\section{Methods}\label{sec:methods}
See Section~\ref{sec:methods} on page~\pageref{sec:methods}.hyperref\autoref{sec:methods}\label\captionThis has a footnote.\footnote{Footnote text here.}Inline: $E = mc^2$ or \(E = mc^2\)
Display:
\[ E = mc^2 \]
% Numbered equation:
\begin{equation}\label{eq:einstein}
E = mc^2
\end{equation}\usepackage{amsmath} % align, cases, matrices, etc.
\usepackage{amssymb} % extra symbols (ℝ, ℤ, etc.)
\usepackage{mathtools} % extends amsmath (dcases, coloneqq, etc.)% Fractions
\frac{a}{b} \dfrac{a}{b} (display-size)
% Roots
\sqrt{x} \sqrt[3]{x}
% Sub/superscripts
x_{i} x^{2} x_{i}^{2} a_{i,j}
% Sums, products, integrals
\sum_{i=1}^{n} x_i \prod_{i=1}^{n} x_i
\int_{0}^{\infty} f(x)\,dx
\lim_{x \to \infty} f(x)
% Brackets (auto-sized)
\left( \frac{a}{b} \right)
\left[ ... \right]
\left\{ ... \right\}\begin{pmatrix} a & b \\ c & d \end{pmatrix} % (a b; c d)
\begin{bmatrix} a & b \\ c & d \end{bmatrix} % [a b; c d]
\begin{vmatrix} a & b \\ c & d \end{vmatrix} % |a b; c d| (determinant)
\begin{Bmatrix} a & b \\ c & d \end{Bmatrix} % {a b; c d}\begin{align}
f(x) &= x^2 + 2x + 1 \label{eq:f} \\
g(x) &= x^3 - 1 \label{eq:g}
\end{align}
% No numbering:
\begin{align*}
a &= b + c \\
d &= e + f
\end{align*}f(x) = \begin{cases}
x^2 & \text{if } x \geq 0 \\
-x^2 & \text{if } x < 0
\end{cases}| Lower | Command | Upper | Command |
|---|---|---|---|
| α | | Α | |
| β | | Β | |
| γ | | Γ | |
| δ | | Δ | |
| ε | | Ε | |
| θ | | Θ | |
| λ | | Λ | |
| μ | | — | — |
| π | | Π | |
| σ | | Σ | |
| φ | | Φ | |
| ω | | Ω | |
| Symbol | Command | Symbol | Command |
|---|---|---|---|
| ≤ | | ≥ | |
| ≠ | | ≈ | |
| ± | | × | |
| ÷ | | · | |
| ∈ | | ∉ | |
| ⊂ | | ⊆ | |
| ∪ | | ∩ | |
| ∞ | | ∂ | |
| ∇ | | ∀ | |
| ∃ | | → | |
| ⇒ | | ⇔ | |
| ℝ | | ℤ | |
| … | |
\begin{table}[htbp]
\centering
\caption{Results summary}\label{tab:results}
\begin{tabular}{lcrp{4cm}}
\toprule
Name & Count & Score & Description \\
\midrule
Alpha & 10 & 95.2 & First entry \\
Beta & 20 & 87.1 & Second entry \\
\bottomrule
\end{tabular}
\end{table}| Spec | Alignment |
|---|---|
| Left |
| Center |
| Right |
| Paragraph (top-aligned, fixed width) |
| Middle-aligned paragraph (requires |
| ` | ` |
\usepackage{booktabs} % \toprule, \midrule, \bottomrule (professional rules)
\usepackage{multirow} % \multirow{nrows}{width}{text}
\usepackage{longtable} % tables spanning multiple pages
\usepackage{tabularx} % auto-width X columns\multicolumn{3}{c}{Spanning header} \\
\multirow{2}{*}{Tall cell}\usepackage{graphicx}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{images/photo.png}
\caption{A descriptive caption.}\label{fig:photo}
\end{figure}| Option | Example |
|---|---|
| |
| |
| |
| |
| |
| Specifier | Meaning |
|---|---|
| Here (approximately) |
| Top of page |
| Bottom of page |
| Dedicated float page |
| Override internal limits |
| Exactly here (requires |
\usepackage{subcaption}
\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.48\textwidth}
\includegraphics[width=\textwidth]{img1.png}
\caption{First}\label{fig:sub1}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.48\textwidth}
\includegraphics[width=\textwidth]{img2.png}
\caption{Second}\label{fig:sub2}
\end{subfigure}
\caption{Both images}\label{fig:both}
\end{figure}references.bib@article{smith2023,
author = {Smith, John and Doe, Jane},
title = {An Important Paper},
journal = {Journal of Examples},
year = {2023},
volume = {42},
pages = {1--15},
doi = {10.1234/example}
}
@book{knuth1984,
author = {Knuth, Donald E.},
title = {The {\TeX}book},
publisher = {Addison-Wesley},
year = {1984}
}\usepackage{natbib} % or use biblatex
\bibliographystyle{plainnat}
As shown by \citet{smith2023}... % Smith and Doe (2023)
This is known \citep{smith2023}. % (Smith and Doe, 2023)
\bibliography{references}pdflatex → bibtex → pdflatex → pdflatex\usepackage[backend=biber, style=authoryear]{biblatex}
\addbibresource{references.bib}
\textcite{smith2023} % Smith and Doe (2023)
\parencite{smith2023} % (Smith and Doe, 2023)
\printbibliographypdflatex → biber → pdflatex → pdflatex| Feature | natbib | biblatex |
|---|---|---|
| Backend | BibTeX | Biber (recommended) |
| Flexibility | Limited styles | Highly customizable |
| Unicode | Poor | Full support |
| Recommendation | Legacy projects | New projects |
\begin{verbatim}
def hello():
print("Hello, world!")
\end{verbatim}
Inline: \verb|some_code()|\usepackage{listings}
\usepackage{xcolor}
\lstdefinestyle{mystyle}{
basicstyle=\ttfamily\small,
keywordstyle=\color{blue},
commentstyle=\color{gray},
stringstyle=\color{red},
numbers=left,
numberstyle=\tiny,
frame=single,
breaklines=true
}
\begin{lstlisting}[language=Python, style=mystyle, caption={Example}]
def factorial(n):
"""Compute factorial."""
if n <= 1:
return 1
return n * factorial(n - 1)
\end{lstlisting}\usepackage{minted}
\begin{minted}[linenos, frame=lines, fontsize=\small]{python}
def factorial(n):
if n <= 1:
return 1
return n * factorial(n - 1)
\end{minted}pdflatex -shell-escape document.tex\documentclass{beamer}
\usetheme{Madrid} % or: Berlin, Warsaw, Metropolis, etc.
\usecolortheme{default} % or: beaver, crane, dolphin, etc.
\title{My Presentation}
\author{Author}
\date{\today}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}{Outline}
\tableofcontents
\end{frame}
\section{Introduction}
\begin{frame}{Introduction}
\begin{itemize}
\item<1-> First point (appears on slide 1+)
\item<2-> Second point (appears on slide 2+)
\item<3-> Third point
\end{itemize}
\end{frame}
\begin{frame}{With Columns}
\begin{columns}
\begin{column}{0.5\textwidth}
Left content
\end{column}
\begin{column}{0.5\textwidth}
Right content
\end{column}
\end{columns}
\end{frame}
\end{document}MadridBerlinMetropolisWarsawCambridgeUS| Command | Effect |
|---|---|
| Show content incrementally |
| Show on slide 2 only |
| Only on slide 1 (no space reserved) |
| Visible from slide 2 onward |
| Highlighted on slide 2 |
\usepackage[margin=2.5cm]{geometry}
% or:
\usepackage[top=3cm, bottom=3cm, left=2cm, right=2cm]{geometry}\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all
\fancyhead[L]{Left Header}
\fancyhead[R]{\rightmark} % current section
\fancyfoot[C]{\thepage} % page number center
\renewcommand{\headrulewidth}{0.4pt}\pagenumbering{roman} % i, ii, iii (for front matter)
\pagenumbering{arabic} % 1, 2, 3 (for main content)
\thispagestyle{empty} % no number on this page\usepackage{multicol}
\begin{multicols}{2}
Content in two columns...
\end{multicols}| Package | Purpose |
|---|---|
| Enhanced math environments |
| Extra math symbols (ℝ, ℤ, etc.) |
| Extensions to amsmath |
| Image inclusion |
| Clickable links, PDF metadata |
| Page margins and dimensions |
| Professional table rules |
| Multi-row table cells |
| Multi-page tables |
| Auto-width table columns |
| Color support |
| Code listings |
| Syntax-highlighted code (needs Pygments) |
| Programmatic graphics and diagrams |
| Data plots (built on TikZ) |
| Custom headers/footers |
| Line spacing |
| Customize list environments |
| Subfigures and subtables |
| Extra float control ( |
| Language/hyphenation support |
| Input encoding ( |
| Font encoding ( |
| Microtypographic enhancements |
| Smart cross-references ( |
| SI units and number formatting |
| Algorithm pseudocode |
| Citation management |
| Modern bibliography management |
| Context-sensitive quotation marks |
| Typeset URLs |
| Customize caption formatting |
| Appendix management |
hyperrefcleverefhyperref| Engine | Use when |
|---|---|
| Default. Most compatible. ASCII/Latin input. |
| System fonts (TTF/OTF), full Unicode |
| System fonts + Lua scripting, full Unicode |
# Basic document
pdflatex document.tex
# With bibliography (BibTeX)
pdflatex document.tex
bibtex document
pdflatex document.tex
pdflatex document.tex
# With bibliography (Biber/BibLaTeX)
pdflatex document.tex
biber document
pdflatex document.tex
pdflatex document.tex
# Automated (recommended)
latexmk -pdf document.tex # pdflatex
latexmk -xelatex document.tex # xelatex
latexmk -lualatex document.tex # lualatex
latexmk -pdf -pvc document.tex # continuous preview| Error | Cause | Fix |
|---|---|---|
| Typo or missing package | Check spelling; add |
| Math symbol outside math mode | Wrap in |
| Error in preamble | Check preamble for typos |
| Wrong path or missing file | Check filename/path, check extension |
| Line too wide | Rephrase, add |
| Missing bib entry or no bibtex run | Run bibtex/biber, check .bib keys |
| Too many figures queued | Add |
| Image scaling issue | Check |
| Two packages conflict | Load one, check docs for compatibility |
.log!LaTeX Warning:Package xyz Warning:Rerun to get cross-references right\input{chapters/intro}\include{chapters/intro}\clearpage\includeonlypreamble.stypreamble.tex\input{preamble}\caption{...}\label{fig:x}Figure~\ref{fig:x}Section~\ref{sec:y}\documentclass[draft]{article}\centeringcenter\\booktabs\hlinemicrotypecleveref\cref{fig:x}| Task | Command |
|---|---|
| Bold | |
| Italic | |
| Monospace | |
| Section | |
| Reference | |
| Citation | |
| Footnote | |
| Image | |
| URL | |
| List item | |
| New page | |
| Comment | |
| Math inline | |
| Math display | |
| Fraction | |
| Command | Symbol | Command | Symbol |
|---|---|---|---|
| sin | | cos |
| tan | | log |
| ln | | exp |
| min | | max |
| lim | | Σ |
| Π | | ∫ |
| Command | Symbol |
|---|---|
| → |
| ← |
| ↔ |
| ⇒ |
| ⇐ |
| ⇔ |
| ↦ |
| ↑ |
| ↓ |