Getting Started
Understanding the LaTeX Preamble and Document Structure
Every LaTeX document has two parts: the preamble (settings/packages) and the document body (content). Understanding this structure is key to customizing your documents.
Document Structure
The two main parts:
% ===== PREAMBLE (before \begin{document}) =====
\documentclass[12pt]{article} % Document type
\usepackage{graphicx} % Packages
\title{My Paper} % Metadata
\author{John Smith}
% ===== BODY (between begin/end document) =====
\begin{document}
\maketitle
Your content goes here...
\end{document}Document Class
First line - sets document type:
% Basic classes:
\documentclass{article} % Short documents
\documentclass{report} % Chapters, longer works
\documentclass{book} % Two-sided, chapters
\documentclass{letter} % Letters
% With options:
\documentclass[12pt,a4paper,twocolumn]{article}
% Journal classes:
\documentclass{IEEEtran}
\documentclass{elsarticle}Loading Packages
Add features with \usepackage:
% Essential packages:
\usepackage{graphicx} % Images
\usepackage{amsmath} % Math features
\usepackage{hyperref} % Clickable links
\usepackage{geometry} % Page layout
\usepackage{biblatex} % Modern citations
% Package with options:
\usepackage[margin=1in]{geometry}
\usepackage[colorlinks=true]{hyperref}Custom Commands
Define shortcuts in preamble:
% Custom commands save typing:
\newcommand{\R}{\mathbb{R}} % \R → ℝ
\newcommand{\vect}[1]{\mathbf{#1}} % \vect{x} → x (bold)
% Then in document:
Let $x \in \R$ and $\vect{v}$ be a vector.💡 Tips
- •Keep preamble organized: class, packages, custom commands, metadata
- •Package order can matter - load hyperref last usually
- •For large projects, put preamble in a separate .tex file and \input it
Try This in Bibby AI
Write LaTeX faster with AI auto-complete and instant compilation.
Start Writing Free