Internationalization
LaTeX requires some additional configuration to typeset documents in languages other than English. In addition, many scripts require LuaTeX, which is currently the recommended engine, or XeTeX.
There are currently two packages providing international language support:
- Babel works with the three main engines: pdfTeX, LuaTeX and XeTeX. It's part of the LaTeX core, and the recommended package by The LaTeX Companion (3rd ed., 2023). Depending on the engine the number of supported languages goes from about 170 to 300, covering about 45 scripts.
- Polyglossia was devised as an alternative to Babel for XeTeX (although provides partial support for LuaTeX). It supports about 90 languages, covering about 30 scripts.
Both packages cover the major languages around the World (French, Spanish, Arabic, Chinese, Japanese, Thai, Hindi, Marathi, etc.) and handle the following tasks:
- Fonts: Assigning a font to each non-Latin language
- Linebreaking, justification and hyphenation: Activating for each script and language the corresponding line breaking algorithm
- Cultural elements: Translating document labels, formatting dates and numbers
- Bidirectional typesetting: Supporting documents that contain right to left scripts
- Typographical rules and transliterations: Performing miscellaneous transformations
With Babel, LaTeX >= 2018-04-01, and a monolingual document in UTF-8 encoding:
\documentclass[french]{article}
\usepackage[T1]{fontenc} % <- With XeTeX or LuaTeX, delete this line
\usepackage{babel}
\begin{document}
Plus ça change, plus c'est la même chose!
\end{document}
Encodings
Unicode Engines
When using the xelatex or lualatex engines, many of the problems are solved for you. Input files are assumed to be UTF-8, and the engine automatically maps Unicode characters to their glyphs in the TrueType or OpenType fonts you selected.
Fonts are configured using the fontspec package. Here is an example for Hindi:
\documentclass[hindi]{article}
\usepackage{babel}
\babelfont{rm}{Shobhika}
\begin{document}
जिस की लाठी उस की भैंस.
\end{document}
8-bit Engines
With engines not supporting Unicode internally (latex or pdflatex), LaTeX must handle two fundamental problems:
- Mapping the bytes of your input file into the characters of the language(s) you want to use.
- Mapping those characters to their glyphs in the fonts your document uses.
For most Latin languages, T1 is the desired output encoding:
\usepackage[T1]{fontenc}
Babel
The core package babel supports the 3 main engines (PDFLaTeX, LuaLaTeX and XeLaTeX). There are two ways to specify the document languages:
\usepackage[language]{babel}
Or making the language a global option:
\documentclass[language]{article}
\usepackage{babel}
If you call babel with multiple languages:
\usepackage[languageA,languageB]{babel}
The last language in the option list will be active, and you can use:
\selectlanguage{languageA}
to change the active language. You can also add short pieces of text in another language:
\foreignlanguage{languageB}{Text in another language}
Babel also offers various environments for entering larger pieces of text in another language:
\begin{otherlanguage}{languageB}
Text in language B. This environment switches all language-related definitions.
\end{otherlanguage}
Font Management
Babel supports OpenType fonts with fontspec. It provides the macro \babelfont:
\babelfont{rm}{FreeSerif}
If you have to resort to different fonts:
\babelfont{rm}{Iwona}
\babelfont[hebrew]{rm}{FreeSerif}
Bidirectional Texts
Babel provides basic support for bidirectional texts. With bidi=basic RTL and LTR text can be mixed without explicit markup (only LuaTeX).
Customization
Babel provides tools to customize the behavior of languages:
\setlocalecaption{spanish}{contents}{Contenidos}
Multilingual Versions
It is possible in LaTeX to typeset the content of one document in several languages and to choose upon compilation which language to output. With:
\babeltags{de = german}
You can write:
text \textde{German text} text
The current language can be tested using the iflang package:
\IfLanguageName{ngerman}{Hallo}{Hello}
Polyglossia
Besides the core babel package, polyglossia can be used as an alternative with XeLaTeX and LualaTeX.
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage[variant=american]{english}
\setotherlanguages{french, bulgarian, greek}
\newfontfamily\bulgarianfont
{NewComputerModern10}[Script=Cyrillic,Language=Bulgarian]
\newfontfamily\greekfont
{NewComputerModern10}[Script=Greek,Language=Greek]
\begin{document}
English. \textlang{french}{French}. \textlang{bulgarian}{Български}.
\textlang{greek}{Ελληνικά}.
\end{document}
As a comparison, here is the code with babel:
\documentclass{article}
\usepackage[american]{babel}
\babelfont[*cyrillic, *greek]{rm}{NewComputerModern10}
\begin{document}
English. \foreignlanguage{french}{French}.
\foreignlanguage{bulgarian}{Български}. \foreignlanguage{greek}{Ελληνικά}.
\end{document}
Specific Languages
Here is a collection of language-specific suggestions.
Arabic Script
Documents in the Arabic script, including Arabic, Persian, Urdu, Pashto, Kurdish, Uyghur, etc., are best typeset with either XeTeX or LuaTeX:
\documentclass{article}
\usepackage[bidi=basic]{babel}
\babelprovide[import, main]{arabic}
\babelfont{rm}{FreeSerif}
\begin{document}
وقد عرفت شبه جزيرة العرب طيلة العصر الهيليني (الأغريقي)
\end{document}
Cyrillic Script
Currently the most convenient way to typeset Cyrillic texts is with XeTeX or LuaTeX:
\documentclass{article}
\usepackage[russian]{babel}
\babelfont{rm}{DejaVu Serif}
\begin{document}
Россия, находящаяся на пересечении множества культур...
\end{document}
Support for Cyrillic in non-Unicode engines:
\usepackage{amsmath,amsthm,amssymb}
\usepackage{mathtext}
\usepackage[T1,T2A]{fontenc}
\usepackage[english,bulgarian,russian,ukrainian]{babel}
Chinese
Typesetting Chinese texts is best done with a complete framework like CJK or xeCJK.
CJK Package
\documentclass{article}
\usepackage{CJK}
\begin{document}
\begin{CJK}{UTF8}{gbsn}
你好
You can mix Latin letters and Chinese.
\end{CJK}
\end{document}
xeCJK Package
\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{FZSSK.ttf}
\begin{document}
你好
You can still mix Latin letters and Chinese!
\end{document}
French
As of version 3.0 of babel-french, it is advised to choose the language as a global option:
\documentclass[french]{article}
\usepackage{babel}
German
\documentclass[ngerman]{article}
\usepackage{babel}
Japanese
For Japanese, the recommended approach is using LuaTeX with luatexja:
\documentclass{article}
\usepackage{luatexja}
\setmainjfont{Noto Serif CJK JP}
\begin{document}
日本語の文書を作成します。
\end{document}
Korean
\documentclass{article}
\usepackage{kotex}
% or with XeTeX/LuaTeX
\usepackage{xeCJK}
\setCJKmainfont{NanumGothic}