1---
2name: latex
3description: Write LaTeX documents with correct syntax, packages, and compilation workflow.
4metadata:
5 source: https://skillmd.com/skills/modbender/latex
6 clawdbot:
7 emoji: 📐
8 os:
9 - linux
10 - darwin
11 - win32
12---
13
14## Special Characters
15
16- Reserved chars need escape: `\# \$ \% \& \_ \{ \} \textbackslash`
17- Tilde as character: `\textasciitilde` not `\~` (that's an accent)
18- Caret: `\textasciicircum` not `\^`
19- Backslash in text: `\textbackslash` not `\\` (that's line break)
20
21## Quotes & Dashes
22
23- Opening quotes: ``` `` ``` not `"`; closing: `''`—never use straight `"` quotes
24- Hyphen `-`, en-dash `--` (ranges: 1--10), em-dash `---` (punctuation)
25- Minus in math mode: `$-1$` not `-1` in text
26
27## Math Mode
28
29- Inline: `$...$` or `\(...\)`; display: `\[...\]` or `equation` environment
30- Text inside math: `$E = mc^2 \text{ where } m \text{ is mass}$`
31- Multiline equations: `align` environment, not multiple `equation`s
32- `\left( ... \right)` for auto-sizing delimiters—must be paired
33
34## Spacing
35
36- Command followed by text needs `{}` or `\ `: `\LaTeX{}` or `\LaTeX\ is`
37- Non-breaking space: `~` between number and unit: `5~km`
38- Force space in math: `\,` thin, `\:` medium, `\;` thick, `\quad` `\qquad`
39
40## Packages
41
42- `\usepackage` order matters—`hyperref` almost always last
43- `inputenc` + `fontenc` for UTF-8: `\usepackage[utf8]{inputenc}` `\usepackage[T1]{fontenc}`
44- `graphicx` for images, `booktabs` for professional tables, `amsmath` for advanced math
45- `microtype` for better typography—load early, subtle but significant improvement
46
47## Floats (Figures & Tables)
48
49- `[htbp]` suggests placement: here, top, bottom, page—not commands
50- LaTeX may move floats far from source—use `[H]` from `float` package to force
51- Always use `\centering` inside float, not `center` environment
52- Caption before `\label`—label references the last numbered element
53
54## References
55
56- Compile twice to resolve `\ref` and `\pageref`—first pass collects, second uses
57- `\label` immediately after `\caption` or inside environment being labeled
58- For bibliography: latex → bibtex → latex → latex (4 passes)
59- `hyperref` makes refs clickable—but can break with some packages
60
61## Tables
62
63- `tabular` for inline, `table` float for numbered with caption
64- Use `booktabs`: `\toprule`, `\midrule`, `\bottomrule`—no vertical lines
65- `@{}` removes padding: `\begin{tabular}{@{}lll@{}}`
66- Multicolumn: `\multicolumn{2}{c}{Header}`; multirow needs `multirow` package
67
68## Images
69
70- Path relative to main file or set with `\graphicspath{{./images/}}`
71- Prefer PDF/EPS for pdflatex/latex; PNG/JPG for photos
72- `\includegraphics[width=0.8\textwidth]{file}`—no extension often better
73
74## Common Errors
75
76- Overfull hbox: line too long—rephrase, add `\-` hyphenation hints, or allow `\sloppy`
77- Missing `$`: math command used in text mode
78- Undefined control sequence: typo or missing package
79- `\include` adds page break, `\input` doesn't—use `\input` for fragments
80
81## Document Structure
82
83- Preamble before `\begin{document}`—all `\usepackage` and settings
84- `\maketitle` after `\begin{document}` if using `\title`, `\author`, `\date`
85- `article` for short docs, `report` for chapters without parts, `book` for full books