Typevia
Multilingual Documents

Understanding Multilingual Support in LaTeX

By default, LaTeX is configured for English. While you can type non-English characters directly into your editor, LaTeX needs specific instructions to handle them correctly. Multilingual support in LaTeX involves more than just displaying accents; it includes:

  1. Hyphenation: Every language has unique rules for breaking words at the end of a line.
  2. Document Strings: Automatically generated text like "Table of Contents," "Chapter," and "References" must be translated.
  3. Typography: Rules for spacing (e.g., French spacing before colons) and punctuation vary by language.
  4. Character Encoding: Ensuring the computer understands symbols like ñ, ç, or ß.

To manage these requirements, we primarily use two packages: babel (for standard LaTeX/pdfLaTeX) and polyglossia (for modern engines like XeLaTeX and LuaLaTeX).


The Standard Approach: Using the Babel Package

The babel package is the industry standard for multilingual documents in LaTeX. It supports a vast array of languages and manages hyphenation and translations automatically.

Basic Syntax

To use babel, you load it in your preamble and list the languages you intend to use. The last language listed becomes the default language of the document.

\documentclass{article}
\usepackage[utf8]{inputenc} % Allows UTF-8 input
\usepackage[T1]{fontenc}    % Better font encoding for accents
\usepackage[french, german, english]{babel} % English is the default

\begin{document}

This document is in English. LaTeX will use English hyphenation 
and call the bibliography "References."

\end{document}

Note: Modern LaTeX distributions (since 2018) handle \usepackage[utf8]{inputenc} automatically, but including it ensures compatibility with older systems.

Switching Languages

If you are writing a document in one language but need a few paragraphs or words in another, you can switch languages mid-document using two main commands:

  1. \selectlanguage{name}: Changes the language for the rest of the document.
  2. \begin{otherlanguage}{name}: Changes the language for a specific block of text.
  3. \foreignlanguage{name}{text}: Changes the language for a short phrase.

Example: Switching Languages

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french, english]{babel}

\begin{document}

\section{Introduction}
This paragraph is in English.

\selectlanguage{french}
\section{Introduction en Français}
Ce paragraphe est en français. Remarquez comment LaTeX gère 
automatiquement l'espacement avant les deux-points : comme ceci.

\begin{otherlanguage}{english}
Back to English for a moment to discuss French typography.
\end{otherlanguage}

\end{document}

Working with Non-Latin Scripts

If your document requires scripts like Greek, Cyrillic, or Arabic, simply loading babel is often not enough. You must also ensure your font encoding supports these characters.

For Cyrillic (Russian, Bulgarian, etc.), you typically use the T2A encoding:

\documentclass{article}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}

\begin{document}
Привет, мир! % "Hello, World!" in Russian
\end{document}

Warning: Using standard pdfLaTeX with complex scripts (like Arabic or Hindi) or East Asian languages (Chinese, Japanese, Korean - CJK) can be quite difficult and often requires specialized packages like CJKutf8. For these use cases, we highly recommend switching to XeLaTeX or LuaLaTeX.


The Modern Way: XeLaTeX and Polyglossia

If you need to use many different languages or specific system fonts (like Arial, Times New Roman, or specialized scripts), the combination of XeLaTeX and the polyglossia package is the modern gold standard.

XeLaTeX uses Unicode natively, meaning you can type any character from any language directly into your editor, provided you have a font that supports it.

Using Polyglossia

Instead of babel, we use polyglossia. Instead of fontenc, we use fontspec.

% Compile this with XeLaTeX or LuaLaTeX
\documentclass{article}
\usepackage{polyglossia}
\usepackage{fontspec}

% Set the main language
\setmainlanguage{english}
\setotherlanguage{greek}

% Choose a font that supports both Latin and Greek scripts
\setmainfont{Times New Roman} 

\begin{document}

In English, we call it the "alphabet." 
In Greek, it is \textgreek{αλφάβητος}.

\end{document}

Key Advantages of Polyglossia/XeLaTeX:

  • System Fonts: Use any .ttf or .otf font installed on your computer.
  • Easy Right-to-Left (RTL): Better support for Hebrew, Arabic, and Persian.
  • Unicode Support: No more worrying about complex font encodings (T1, T2A, etc.).

Right-to-Left (RTL) Languages

Writing in languages like Arabic or Hebrew requires the text to flow from right to left. While babel has added support for this recently, polyglossia (with XeLaTeX) remains the most robust method for beginners.

% Compile with XeLaTeX
\documentclass{article}
\usepackage{polyglossia}
\usepackage{fontspec}

\setmainlanguage{english}
\setotherlanguage{arabic}

% You must choose a font that actually contains Arabic characters
\newfontfamily\arabicfont[Script=Arabic]{Amiri} 

\begin{document}

The English word for "Book" is translated into Arabic as:
\begin{Arabic}
كتاب
\end{Arabic}

\end{document}

Best Practices and Common Pitfalls

To ensure your multilingual documents compile correctly and look professional, follow these guidelines:

1. Always Check Your Font

Not all fonts contain characters for all languages. If you see "missing character" warnings or empty boxes (tofu) in your PDF, your font likely doesn't support that script.

2. Order Matters in Babel

When loading babel, remember that the last language in the list is the primary one.

  • Correct: \usepackage[spanish, english]{babel} (Document is English).
  • Incorrect: \usepackage[english, spanish]{babel} (If you intended the document to be English, this will make it Spanish).

3. Use the Correct Compiler

If you are using fontspec or polyglossia, you must change your LaTeX engine/compiler from pdfLaTeX to XeLaTeX or LuaLaTeX in your editor settings (e.g., Typevia, TeXworks, or VS Code).

4. Handling Punctuation

Different languages have different rules for punctuation spacing. For example, French requires a non-breaking space before characters like ;, :, !, and ?. babel handles this automatically, so do not manually add spaces before your punctuation in French, or you might end up with double spaces.

5. Translated Captions

If your "List of Figures" still says "List of Figures" even though you are writing in Italian, ensure you have used \selectlanguage{italian} or loaded italian as the last option in babel.

Summary Table

FeaturepdfLaTeX + BabelXeLaTeX + Polyglossia
Best ForStandard European languagesComplex scripts, RTL, system fonts
SpeedFaster compilationSlightly slower
FontsLimited to TeX font packagesAny system font (.ttf/.otf)
Ease of UseHigh (for Latin scripts)High (for all scripts)
UnicodeRequires inputencNative support