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=ngerman | Names 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}Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → pdflatex.
Pitfalls
- A misspelled language name, or a language whose files are not installed, stops with Unknown option 'germann'. Either you misspelled it or the language definition file germann.ldf was not found.
- With
germanandngermanthe straight double quote is a shorthand character:"aprints ä and"sprints ß. For a plain double quote write\dq. babeldoes not set quotation marks. Use\enquotefromcsquotesfor marks that follow the language.- With pdfLaTeX, load
fontencwithT1as well; otherwise words that contain umlauts or accents are not hyphenated.
Related pages
- How-to Umlauts and accents in LaTeX
- How-to Hyphenation in LaTeX
- How-to Quotation marks in LaTeX
- Package
csquotes - Error Unknown option 'germann'. Either you misspelled it or the language definition file germann.ldf was not found
- How-to Create a bibliography in LaTeX with biblatex and Biber
- How-to Citation styles in LaTeX
- How-to Write a letter in LaTeX
- How-to Set up a thesis in LaTeX
- How-to Create an exercise sheet or exam in LaTeX