Create a minimal document in LaTeX (basic structure)

A LaTeX document starts with \documentclass{article} and puts its content between \begin{document} and \end{document}. The part between the class and \begin{document} is the preamble; packages and settings go there.

The smallest document

These four lines compile to one page with one line of text and a page number.

Complete document:

\documentclass{article}
\begin{document}
Hello, world!
\end{document}
Result
The compiled example

Open in the editor

Choose the class and its options

article is for short texts without chapters, report and book add \chapter, letter is for letters and beamer for slides. The options in brackets set the paper size, the font size (10pt by default, also 11pt and 12pt) and twoside for two-sided printing.

Complete document:

\documentclass[a4paper, 12pt, twoside]{report}
\begin{document}
\chapter{Introduction}
Text of the first chapter.
\end{document}
Result
The compiled example

Open in the editor

A document with the usual packages

fontenc with T1 selects fonts that contain accented letters, babel loads the hyphenation and the fixed words of the language, amsmath adds the math environments, graphicx adds \includegraphics, and hyperref turns references into links. LaTeX reads the file as UTF-8, so no package is needed for the input encoding.

Complete document:

\documentclass[a4paper, 11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}

\title{My First Document}
\author{Anna Schmidt}
\date{\today}

\begin{document}
\maketitle

\section{Introduction}
Text of the first section, with a formula: $E = mc^2$.

\end{document}
Result
The compiled example

Open in the editor

A German document

For German texts, the KOMA-Script class scrartcl (with scrreprt and scrbook) is the usual replacement for article; its layout follows European conventions. ngerman in babel switches hyphenation, date and words such as "Inhaltsverzeichnis" to German.

Complete document:

\documentclass[a4paper, 11pt]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\begin{document}
\section{Einleitung}
Ein Absatz mit Umlauten: ä, ö, ü und ß.
\end{document}
Result
The compiled example

Open in the editor

Pitfalls

Compiled with pdfLaTeX from TeX Live 2023.

Related pages