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

TaskPackageNotes
Page margins and sizegeometry\usepackage[a4paper,margin=1in]{geometry}
Line spacingsetspace\onehalfspacing, \doublespacing (theses)
Colorsxcolor\textcolor{red}{...}, \definecolor
Code listingslistings or mintedminted needs shell escape, which Coauthor's compiler disables; use listings
Algorithmsalgorithm, algpseudocodePseudocode floats
Units and numberssiunitx\SI{3.2}{\milli\second}, \num{1e5}
Diagrams and plotstikz, pgfplotsSee Diagrams with TikZ
Multi-language textbabel\usepackage[english]{babel}
Headers and footersfancyhdrCustom running heads
To-do notestodonotes\todo{check this} in the margin; remove before submission
Floats exactly herefloatEnables [H]
Wide tablestabularx, longtable, pdflscapeSee Tables
Drafts with line numberslineno\linenumbers

Load Order Matters

A few rules avoid most preamble errors:

  1. Fonts and encodings first (inputenc, fontenc, font packages).
  2. hyperref near the end; only cleveref, bookmark, and a handful of others go after it.
  3. Never load the same package twice with different options. If a template already loads hyperref and you add \usepackage[hidelinks]{hyperref}, you get Option clash for package hyperref. Set options afterwards instead: \hypersetup{hidelinks}.
  4. Read the template's instructions before adding geometry, times, or fullpage; 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]
  • \newcommand fails with Command \x already defined if the name exists; use \renewcommand deliberately, never to silence the error.
  • Numbers of arguments go in [n]; refer to them as #1 ... #n.
  • Keep shared macros in a macros.tex that 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:

  1. 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 .cfg all open in the LaTeX editor.
  2. 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

MessageFix
File 'foo.sty' not foundMisspelled name, or a private style file that is not in the project folder
Option clash for package XThe package was already loaded (often by the class); remove your line or move options into a setup command
Can be used only in preambleA \usepackage ended up after \begin{document}, perhaps inside an \input section file
Command \x already definedChoose 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

Your First LaTeX Document
Autocomplete, Snippets, and Find & Replace
Fixing Common LaTeX Errors
Writing for a Venue with Conference and Journal Templates
Multi-File Projects

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.

Ready to Write Better Research Papers?

Let Coauthor help you with your next manuscript

7 days free, with €2.50 of AI usage on your own paper