What goes in a LaTeX preamble: loading packages with \usepackage and options, the packages most papers need, defining your own commands with \newcommand, and where .sty and .cls files live in a Coauthor project.
Packages and the Preamble
The preamble is everything between \documentclass and \begin{document}. It never prints anything; it loads packages, sets options, defines your own commands, and fills in metadata. Almost every "how do I make LaTeX do X" question is answered by a package, and Coauthor's compiler ships with a full TeX Live distribution, so any package on CTAN is already available; you do not install anything.
Loading a Package
\usepackage{graphicx} % no options
\usepackage[margin=2.5cm]{geometry} % key=value options
\usepackage[utf8]{inputenc} % one option
\usepackage{amsmath,amssymb,amsthm} % several packages, no options
In the Coauthor editor, type \usepackage{ and the autocomplete popup lists common packages with a one-line description; pick one with Enter. See Autocomplete, Snippets, and Find & Replace.
A Preamble Most Papers Can Start From
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype} % better spacing, fewer overfull boxes
\usepackage{amsmath,amssymb,amsthm} % math
\usepackage{graphicx,booktabs,subcaption} % figures and tables
\usepackage[margin=2.5cm]{geometry} % layout
\usepackage{enumitem} % tighter lists: \begin{itemize}[noitemsep]
\usepackage[round]{natbib} % citations
\usepackage[colorlinks=true,allcolors=blue]{hyperref} % load these two last
\usepackage[capitalize]{cleveref}
Venue templates already contain most of this in their .sty or .cls file. When you write for a venue, start from the template's preamble and add only what you need; see Writing for a Venue with Conference and Journal Templates.
Packages by Task
| Task | Package | Notes |
|---|---|---|
| Page margins and size | geometry | \usepackage[a4paper,margin=1in]{geometry} |
| Line spacing | setspace | \onehalfspacing, \doublespacing (theses) |
| Colors | xcolor | \textcolor{red}{...}, \definecolor |
| Code listings | listings or minted | minted needs shell escape, which Coauthor's compiler disables; use listings |
| Algorithms | algorithm, algpseudocode | Pseudocode floats |
| Units and numbers | siunitx | \SI{3.2}{\milli\second}, \num{1e5} |
| Diagrams and plots | tikz, pgfplots | See Diagrams with TikZ |
| Multi-language text | babel | \usepackage[english]{babel} |
| Headers and footers | fancyhdr | Custom running heads |
| To-do notes | todonotes | \todo{check this} in the margin; remove before submission |
| Floats exactly here | float | Enables [H] |
| Wide tables | tabularx, longtable, pdflscape | See Tables |
| Drafts with line numbers | lineno | \linenumbers |
Load Order Matters
A few rules avoid most preamble errors:
- Fonts and encodings first (
inputenc,fontenc, font packages). hyperrefnear the end; onlycleveref,bookmark, and a handful of others go after it.- Never load the same package twice with different options. If a template already loads
hyperrefand you add\usepackage[hidelinks]{hyperref}, you getOption clash for package hyperref. Set options afterwards instead:\hypersetup{hidelinks}. - Read the template's instructions before adding
geometry,times, orfullpage; changing the page layout of a venue template is usually forbidden.
Defining Your Own Commands
Macros make notation consistent and easy to change later:
\newcommand{\R}{\mathbb{R}}
\newcommand{\vect}[1]{\mathbf{#1}} % one argument
\newcommand{\norm}[2][2]{\left\lVert #2 \right\rVert_{#1}} % optional arg with default 2
\renewcommand{\vec}[1]{\boldsymbol{#1}} % override an existing command
\DeclareMathOperator*{\argmax}{arg\,max} % upright operator with limits
\newtheorem{theorem}{Theorem}[section]
\newcommandfails withCommand \x already definedif the name exists; use\renewcommanddeliberately, never to silence the error.- Numbers of arguments go in
[n]; refer to them as#1...#n. - Keep shared macros in a
macros.texthat the main file\inputs from the preamble, so every section file and every collaborator uses the same definitions. See Multi-File Projects.
Where .sty and .cls Files Live in Coauthor
If a venue or your institution gives you a style file (neurips_2026.sty, aaai2027.bst, mythesis.cls), put it in the same folder as your main .tex file. Coauthor sends every file in the project folder and its subfolders to the compiler, and TeX looks in the current directory first, so a local .sty overrides the TeX Live version with the same name. To add one:
- Import it with the folder's Import menu item, or create it with Create new document as a LaTeX Document named
venue.sty;.sty,.cls,.bst,.bbx,.cbx,.def,.fd, and.cfgall open in the LaTeX editor. - Reference it without the extension:
\usepackage{venue}or\documentclass{mythesis}.
Style files cannot be the folder's main file. Templates from the gallery ship their style files pre-placed. See LaTeX Editor Overview.
Common Preamble Errors
| Message | Fix |
|---|---|
File 'foo.sty' not found | Misspelled name, or a private style file that is not in the project folder |
Option clash for package X | The package was already loaded (often by the class); remove your line or move options into a setup command |
Can be used only in preamble | A \usepackage ended up after \begin{document}, perhaps inside an \input section file |
Command \x already defined | Choose another name or use \renewcommand |
Missing \begin{document} | Stray text or an unbalanced brace in the preamble |
See Fixing Common LaTeX Errors for how to read them in Coauthor's Compilation Results panel.
Related articles
Prefer to ask?
Inside Coauthor, ask the AI coauthor how any feature works — it answers from these same help articles. For anything else, use the ? button in the top-right corner of the app.