Typevia
Multilingual Documents

Understanding Language Support in LaTeX

By default, LaTeX is configured to produce documents in English. This affects two major areas of your document: hyphenation and localized strings.

If you are writing in a language other than English, or creating a document that uses multiple languages, you will notice that LaTeX might hyphenate words incorrectly or label your "Table of Contents" as "Contents" even if the rest of your text is in German or French.

The babel package is the standard solution for these issues. It adapts LaTeX to the specific typographic rules and naming conventions of dozens of different languages.


Getting Started: Setting the Main Language

To use babel, you load it in your preamble (the area before \begin{document}) and pass the language you want to use as an option.

Basic Syntax

\usepackage[language]{babel}

When you set a language, babel automatically handles:

  1. Hyphenation: It loads the correct patterns so that long words are broken correctly at the end of lines.
  2. Auto-generated names: It translates words like "Chapter," "Index," and "References" into the target language.
  3. Typographic rules: It adjusts spacing (e.g., adding a small space before a colon in French) and date formats.

Example: A Single-Language Document (German)

In this example, the word "Contents" will automatically be replaced with "Inhaltsverzeichnis."

\documentclass{article}

% Specify the language 'ngerman' (New German Spelling)
\usepackage[ngerman]{babel}

\begin{document}
\tableofcontents

\section{Einleitung}
Dies ist ein Beispiel für ein Dokument in deutscher Sprache. 
LaTeX kümmert sich automatisch um die Silbentrennung und die Überschriften.
\end{document}

Note: For many European languages in the traditional pdfLaTeX engine, you should also include \usepackage[T1]{fontenc} to ensure that accented characters are displayed and hyphenated correctly.


Working with Multiple Languages

Many academic documents require the use of multiple languages—for example, an English paper with an abstract in Italian, or a linguistics paper comparing several languages.

When loading babel with multiple languages, the last language in the list becomes the default language for the document.

Switching Languages

There are three primary ways to switch languages within your text:

  1. \selectlanguage{name}: Switches the language from this point forward.
  2. \begin{otherlanguage}{name}: An environment for large blocks of text. It switches everything, including the names of tables and figures.
  3. \foreignlanguage{name}{text}: A command for short, inline phrases. It only affects hyphenation, not document labels.

Example: Multi-language Document

\documentclass{article}
\usepackage[T1]{fontenc}
% English is the secondary language, French is the main language
\usepackage[english, french]{babel}

\begin{document}

\section{Introduction en Français}
Ceci est le texte principal du document. Les règles de ponctuation 
françaises s'appliquent ici.

% Switching to English for a specific paragraph
\begin{otherlanguage}{english}
\section{English Summary}
Even though the main document is French, this section uses English 
hyphenation and rules.
\end{otherlanguage}

\section{Retour au Français}
Nous sommes de retour à la langue principale. On peut aussi insérer 
un mot \foreignlanguage{english}{shortly} en anglais.

\end{document}

Customizing Localized Strings

Sometimes, the default translation provided by babel isn't exactly what you want. For example, you might want "Bibliography" to be titled "Works Cited."

To change these names, you should use the \addto\captions<language> command. This ensures that your change remains active even if you switch languages and come back.

Example: Customizing Labels

\documentclass{article}
\usepackage[english]{babel}

% Customizing the 'Abstract' name to 'Executive Summary'
\addto\captionsenglish{%
  \renewcommand{\abstractname}{Executive Summary}%
  \renewcommand{\contentsname}{Table of Contents}%
}

\begin{document}

\begin{abstract}
This is a summary of the report. Notice the title above.
\end{abstract}

\tableofcontents

\section{Introduction}
Text goes here...

\end{document}

Best Practices and Common Pitfalls

To ensure your document compiles correctly and looks professional, keep these tips in mind:

1. Package Order

Generally, babel should be loaded early in your preamble. However, if you are using the hyperref package (for clickable links), babel should almost always be loaded before hyperref.

2. Language Names

Be precise with language names. For example:

  • Use ngerman for modern German (New Orthography) instead of just german.
  • Use british or american instead of just english if you want specific hyphenation and date rules.
  • Use brazilian or portuguese depending on the region.

3. Font Encoding

If your language uses accents (like á, è, ö, or ç), always include the following in your preamble for pdfLaTeX:

\usepackage[T1]{fontenc}

Without this, LaTeX treats accented characters as a combination of two symbols, which breaks hyphenation and prevents you from copying/pasting text correctly from the resulting PDF.

4. Special Characters in Commands

Some languages (like French) make certain characters like : or ! "active" to handle spacing. This can occasionally break other packages (like tikz). If you encounter strange errors in complex diagrams, you may need to use the command \shorthandoff{:} or load the etoolbox package to manage these conflicts.


Summary of Commands

CommandPurpose
\usepackage[lang]{babel}Loads language support; last lang is default.
\selectlanguage{lang}Switches the current language globally.
\begin{otherlanguage}{lang}Environment for large blocks of foreign text.
\foreignlanguage{lang}{...}Inline command for short foreign phrases.
\addto\captions<lang>{...}Customizes auto-generated labels (like "Table of Contents").
\todayProduces the current date in the format of the active language.

By mastering babel, you ensure that your LaTeX documents meet the professional typographic standards of whatever language you are writing in, providing a better experience for your readers.