1---2name: latex3description: Write LaTeX documents with correct syntax, packages, and compilation workflow.4---56## Special Characters78- Reserved chars need escape: `\# \$ \% \& \_ \{ \} \textbackslash`9- Tilde as character: `\textasciitilde` not `\~` (that's an accent)10- Caret: `\textasciicircum` not `\^`11- Backslash in text: `\textbackslash` not `\\` (that's line break)1213## Quotes & Dashes1415- Opening quotes: ``` `` ``` not `"`; closing: `''`—never use straight `"` quotes16- Hyphen `-`, en-dash `--` (ranges: 1--10), em-dash `---` (punctuation)17- Minus in math mode: `$-1$` not `-1` in text1819## Math Mode2021- Inline: `$...$` or `\(...\)`; display: `\[...\]` or `equation` environment22- Text inside math: `$E = mc^2 \text{ where } m \text{ is mass}$`23- Multiline equations: `align` environment, not multiple `equation`s24- `\left( ... \right)` for auto-sizing delimiters—must be paired2526## Spacing2728- Command followed by text needs `{}` or `\ `: `\LaTeX{}` or `\LaTeX\ is`29- Non-breaking space: `~` between number and unit: `5~km`30- Force space in math: `\,` thin, `\:` medium, `\;` thick, `\quad` `\qquad`3132## Packages3334- `\usepackage` order matters—`hyperref` almost always last35- `inputenc` + `fontenc` for UTF-8: `\usepackage[utf8]{inputenc}` `\usepackage[T1]{fontenc}`36- `graphicx` for images, `booktabs` for professional tables, `amsmath` for advanced math37- `microtype` for better typography—load early, subtle but significant improvement3839## Floats (Figures & Tables)4041- `[htbp]` suggests placement: here, top, bottom, page—not commands42- LaTeX may move floats far from source—use `[H]` from `float` package to force43- Always use `\centering` inside float, not `center` environment44- Caption before `\label`—label references the last numbered element4546## References4748- Compile twice to resolve `\ref` and `\pageref`—first pass collects, second uses49- `\label` immediately after `\caption` or inside environment being labeled50- For bibliography: latex → bibtex → latex → latex (4 passes)51- `hyperref` makes refs clickable—but can break with some packages5253## Tables5455- `tabular` for inline, `table` float for numbered with caption56- Use `booktabs`: `\toprule`, `\midrule`, `\bottomrule`—no vertical lines57- `@{}` removes padding: `\begin{tabular}{@{}lll@{}}`58- Multicolumn: `\multicolumn{2}{c}{Header}`; multirow needs `multirow` package5960## Images6162- Path relative to main file or set with `\graphicspath{{./images/}}`63- Prefer PDF/EPS for pdflatex/latex; PNG/JPG for photos64- `\includegraphics[width=0.8\textwidth]{file}`—no extension often better6566## Common Errors6768- Overfull hbox: line too long—rephrase, add `\-` hyphenation hints, or allow `\sloppy`69- Missing `$`: math command used in text mode70- Undefined control sequence: typo or missing package71- `\include` adds page break, `\input` doesn't—use `\input` for fragments7273## Document Structure7475- Preamble before `\begin{document}`—all `\usepackage` and settings76- `\maketitle` after `\begin{document}` if using `\title`, `\author`, `\date`77- `article` for short docs, `report` for chapters without parts, `book` for full books