The babel package

Adapts a document to its language: hyphenation, generated words such as "Contents" and "Figure", and the date format. \selectlanguage and \foreignlanguage switch between languages.

Loading the package

\usepackage[ngerman]{babel}

Without babel, LaTeX hyphenates every text by English rules and prints English headings such as "Contents", "Figure 1" and "References". The package loads the hyphenation patterns and the translations of the languages named in its options.

When several languages are listed, the last one is the main language of the document, unless main= names another. For German, ngerman stands for the current spelling and german for the rules before 1996: german does not hyphenate "Zucker", ngerman gives "Zu-cker".

The language can also be a class option, as in \documentclass[ngerman]{article}. Other packages that depend on the language, such as csquotes and cleveref, then see it too.

Main commands

\usepackage[english,ngerman]{babel}Loads both languages; the last one, here German, is the main language.
main=ngermanNames the main language, whatever the order of the options.
\selectlanguage{english}Switches hyphenation, generated words and the date format from here on.
\foreignlanguage{english}{text}Hyphenates a short passage by the rules of another language. Generated words and \today keep the surrounding language.
\begin{otherlanguage}{english} ... \end{otherlanguage}Environment with the effect of \selectlanguage, limited to its content.
\babelhyphenation[ngerman]{Staats-ex-amen}Fixes the hyphenation points of single words for one language.

Complete example

\documentclass{article}
\usepackage[english,ngerman]{babel}
\begin{document}
\tableofcontents
\section{Einleitung}
Dieser Text wird nach deutschen Regeln getrennt. Das Datum lautet \today.

\foreignlanguage{english}{This sentence is hyphenated by English rules.}

\selectlanguage{english}
\section{Summary}
From here on the document is English, and the date reads \today.
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → pdflatex.

Pitfalls

Related pages