Languages in LaTeX: babel, polyglossia, Spanish, Arabic and More

Quick answer

  • pdfLaTeX: \usepackage[T1]{fontenc} and \usepackage[spanish]{babel}. Files are read as UTF-8 by default, so type accents directly.
  • XeLaTeX / LuaLaTeX: \usepackage{polyglossia} with \setdefaultlanguage{spanish}, and a font that has the script you need.
  • Switching: \selectlanguage{french} for the rest of the text, \foreignlanguage{french}{...} for a phrase.
  • Hyphenation follows the active language automatically; exceptions go in \babelhyphenation or \hyphenation.
\documentclass{article}
\usepackage[T1]{fontenc}        % accented letters as real glyphs
\usepackage[spanish]{babel}     % Spanish captions, dates and hyphenation

\begin{document}

\tableofcontents                % titled "Índice"

\section{Introducción}
El niño comió una piña. Hoy es \today.

\end{document}

LaTeX was built for English, but one package switches a document to almost any language: the headings it generates (“Contents”, “Chapter”, “Table”), the date, hyphenation, quotation marks and spacing rules. Which package depends on the compiler: babel for pdfLaTeX, polyglossia (or a modern babel) for XeLaTeX and LuaLaTeX. This guide covers both, then Spanish, French and German, Arabic and Hebrew written right to left, Chinese, Japanese and Korean, Russian and Greek, and the errors each one tends to throw. Every snippet compiles as shown.

babel vs polyglossia: Which Package for Which Compiler

Both packages do the same job. The difference is the engine: pdfLaTeX works with 8-bit fonts and needs a font encoding for each alphabet, while XeLaTeX and LuaLaTeX use system OpenType fonts, so the language package only has to pick the right font and rules.

CompilerLanguage packageFontsGood for
pdfLaTeX\usepackage[spanish]{babel}fontenc: T1 (Latin), T2A (Cyrillic), LGR (Greek)European languages, journal templates
XeLaTeXpolyglossia with \setdefaultlanguagefontspec, any OpenType fontArabic, Hebrew, Indic scripts, CJK with xeCJK
LuaLaTeXbabel with \babelprovide, or polyglossiafontspecMany scripts at once, Japanese with luatexja

The same Spanish document for XeLaTeX or LuaLaTeX, with English as a second language:

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{spanish}
\setotherlanguage{english}

\begin{document}

\section{Introducción}
Texto en español con \textenglish{a few words in English}. Hoy es \today.

\end{document}

Do not load inputenc or fontenc with XeLaTeX or LuaLaTeX; those are pdfLaTeX packages. In Overleaf and Octree, the compiler is chosen in the project settings.

Switching Languages: \selectlanguage, \foreignlanguage and otherlanguage

Load every language you use as a babel option. The last one is the main language of the document. Then switch with three commands:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french,ngerman,english]{babel}   % English is the main language
\babelhyphenation[english]{data-base Oct-ree}   % hyphenation exceptions

\begin{document}

English text, with \foreignlanguage{french}{une phrase en français} inside it.

\begin{otherlanguage}{french}
Un paragraphe en français, avec la date : \today.
\end{otherlanguage}

\selectlanguage{ngerman}
Ab hier ist der Text deutsch, mit deutscher Silbentrennung. \today

\selectlanguage{english}
Back to English.

\end{document}
CommandScopeChanges
\selectlanguage{lang}Until the next switchHyphenation, captions, \today, typographic rules
\begin{otherlanguage}{lang}The environmentSame as \selectlanguage
\foreignlanguage{lang}{text}The argumentHyphenation and rules, not captions or date
\begin{otherlanguage*}{lang}The environmentLike \foreignlanguage, for longer passages

polyglossia uses the same \selectlanguage and otherlanguage, plus a shortcut per language such as \textfrench{...} or \textenglish{...}. To rename a heading in any language, see renaming the table of contents.

LaTeX in Spanish

\usepackage[spanish]{babel} translates every generated word (“Índice”, “Capítulo”, “Figura”, “Referencias”), writes dates as “9 de noviembre de 2026” and loads Spanish hyphenation. A few options change its defaults:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[spanish, es-tabla]{babel}   % "Tabla" instead of "Cuadro"
\usepackage{amsmath}

\begin{document}

\section{Resultados}
Las comillas latinas se escriben <<así>>, y la ñ y las tildes se escriben
directamente: año, acción, pingüino.

\begin{table}[h]
  \centering
  \caption{Datos del experimento}
  \begin{tabular}{lr}
    Muestra & Valor \\
    A       & $3.14$ \\
  \end{tabular}
\end{table}

En matemáticas, $3.14$ se imprime con coma decimal y $\lim$ lleva tilde.
\decimalpoint
Con \verb|\decimalpoint|, $3.14$ vuelve a usar punto.

\end{document}
Option or commandEffect
es-tablaTables are captioned “Tabla” and listed in “Índice de tablas” (the default is “Cuadro”)
\decimalpoint / es-nodecimaldotKeep 3.14 with a point in math (the default prints 3,14)
\unaccentedoperators\lim, \max, \min without the accent (lím, máx, mín by default)
es-noshorthandsTurns off the shorthands for <<, >> and ", which can clash with other packages
mexico instead of spanishMexican conventions, including the decimal point
es-noindentfirstNo indent on the first paragraph after a heading

For accents, ñ, ¿ and ¡ without a Spanish keyboard (\'a, \~n, ?`, !`), see Spanish characters in LaTeX and the special characters guide. If TikZ arrows break after loading Spanish, add \usetikzlibrary{babel} (see the errors table below).

French and German: Quotes, \og and Hyphenation

French babel adds the thin space French typography puts before ; : ! ?, and \og … \fg{} print guillemets with the right spacing. German (ngerman for the reformed spelling) adds shorthands such as "` … "' for „German quotes“ and "- for an extra hyphenation point:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ngerman,french]{babel}      % French is the main language
\usepackage[autostyle]{csquotes}        % \enquote picks the right quotes

\begin{document}

Il a dit : \og Bonjour ! \fg{} Puis il est parti ; quel dommage !

\enquote{Citation automatique} en français.

\begin{otherlanguage}{ngerman}
Er sagte: "`Guten Tag!"' und ging. \glqq Auch so\grqq{} geht es.

\enquote{Automatische Anführungszeichen} auf Deutsch.

Donau"-dampf"-schiff"-fahrt hat zusätzliche Trennstellen.
\end{otherlanguage}

\end{document}

csquotes is the most portable option: \enquote{...} always produces the quotation marks of the current language. More on quotation marks in quotes in LaTeX.

Arabic and Hebrew: Right-to-Left Text

Arabic and Hebrew need XeLaTeX (or LuaLaTeX), a font with the script, and a package that handles right-to-left direction. With polyglossia, declaring the language loads bidi for you, and \arabicfont or \hebrewfont tells it which font to use:

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguages{arabic, hebrew}

% Amiri and FreeSerif ship with TeX Live; any installed font with the script works,
% e.g. \newfontfamily\arabicfont[Script=Arabic]{Amiri}
\newfontfamily\arabicfont[Script=Arabic, Extension=.ttf,
  UprightFont=*-Regular, BoldFont=*-Bold]{Amiri}
\newfontfamily\hebrewfont[Script=Hebrew]{FreeSerif.otf}

\begin{document}

English text with an Arabic phrase: \textarabic{مرحبا بالعالم}.

\begin{Arabic}
هذه فقرة كاملة باللغة العربية، تُكتب من اليمين إلى اليسار. \textbf{نص عريض}.
\end{Arabic}

And Hebrew: \texthebrew{שלום עולם}.

\end{document}

For a document that is mainly in Arabic, swap the roles: \setdefaultlanguage{arabic} and \setotherlanguage{english}; headings, numbering and the table of contents then run right to left. Older alternatives exist: arabtex works with pdfLaTeX but expects a Latin transliteration as input, and arabxetex is a XeLaTeX package with its own arab environment. With LuaLaTeX, modern babel handles Arabic through \babelprovide[import]{arabic} and the bidi=basic option.

Chinese, Japanese and Korean

Chinese is simplest with the ctex classes, which set up fonts, line breaking and Chinese headings in one line. Compile with XeLaTeX:

\documentclass[fontset=fandol]{ctexart}   % Fandol fonts ship with TeX Live

\begin{document}

\section{简介}
你好,世界!这是一个中文文档。\today

\end{document}

Leave out fontset=fandol and ctex picks fonts for your operating system. To keep an ordinary class and add CJK text to it, use xeCJK:

\documentclass{article}
\usepackage{xeCJK}
% With an installed font: \setCJKmainfont{Noto Serif CJK SC}
\setCJKmainfont{FandolSong}[Extension=.otf, UprightFont=*-Regular, BoldFont=*-Bold]

\begin{document}
English and 中文 in one line, with \textbf{粗体} for bold.
\end{document}

With pdfLaTeX, the CJKutf8 package works without font setup: wrap the text in \begin{CJK}{UTF8}{gbsn} ... \end{CJK} (gbsn and gkai for simplified Chinese, bsmi for traditional, min for Japanese, mj for Korean). Japanese documents are usually written with LuaLaTeX and luatexja, or the bxjsarticle class; Korean with kotex.

Russian and Greek: T2A and LGR Encodings

pdfLaTeX needs a font encoding for each non-Latin alphabet: T2A for Cyrillic, LGR for Greek. List it in fontenc, with the encoding of the main language last:

\documentclass{article}
\usepackage[T2A,T1]{fontenc}             % Cyrillic and Latin (pdfLaTeX)
\usepackage{PTSerif}                     % a serif font with Cyrillic glyphs
\usepackage[russian,english]{babel}

\begin{document}
English text, and then \foreignlanguage{russian}{Привет, мир!}

\selectlanguage{russian}
\section{Введение}
Сегодня \today.
\end{document}
\documentclass{article}
\usepackage[LGR,T1]{fontenc}             % Greek and Latin (pdfLaTeX)
\usepackage[greek,english]{babel}

\begin{document}
English, then \foreignlanguage{greek}{Καλημέρα κόσμε}.
\end{document}

With XeLaTeX or LuaLaTeX, skip the encodings and pick a font that covers Cyrillic and Greek. Latin Modern does not, so the default font prints nothing for those letters:

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{russian}
\setotherlanguages{english, greek}
% FreeSerif ships with TeX Live; an installed font works by name, e.g. \setmainfont{CMU Serif}
\setmainfont{FreeSerif}[Extension=.otf, BoldFont=*Bold, ItalicFont=*Italic, BoldItalicFont=*BoldItalic]

\begin{document}
\section{Введение}
Текст на русском, \textgreek{λίγα ελληνικά} и \textenglish{some English}.
\end{document}

Greek letters in math need none of this: \alpha and \Omega work in any language (see the Greek alphabet in LaTeX).

Common Errors and Fixes

Message or symptomCauseFix
Package babel Error: Unknown option 'spansh'. Suggested actions: Make sure you haven't misspelled itMisspelled language name, or a name babel does not knowCheck the spelling: spanish, ngerman, french, russian; for newer languages use \babelprovide
LaTeX Error: Unicode character П (U+041F) not set up for use with LaTeXCyrillic or Greek letters under pdfLaTeX without the font encoding\usepackage[T2A,T1]{fontenc} (or LGR for Greek), or switch to XeLaTeX
Arabic, Chinese or Cyrillic text shows boxes or is blank; log says Missing character: There is no … in font lmroman10-regularThe font has no glyphs for that scriptSet a font that has them: \arabicfont, \setCJKmainfont, \setmainfont
Package polyglossia Error: The current main roman font, lmroman10-regular, does not contain the "Arabic" script!No \arabicfont defined\newfontfamily\arabicfont[Script=Arabic]{Amiri}
Package fontspec Error: The font "Amiri" cannot be foundThe font is not installed under that name, or you compiled with pdfLaTeXCompile with XeLaTeX; use an installed font name or the file name (Amiri-Regular.ttf)
Argument of \language@active@arg> has an extra } in a TikZ picturebabel shorthands (Spanish < >, French : !) clash with TikZ syntax\usetikzlibrary{babel}, or es-noshorthands for Spanish
No hyphenation patterns were preloaded for the language … (babel warning)The TeX installation has no patterns for that languageInstall the language collection (e.g. collection-langspanish); Overleaf and Octree have all of them
Spanish tables are captioned “Cuadro”babel's traditional Spanish default\usepackage[spanish, es-tabla]{babel}
\renewcommand{\contentsname}{...} has no effectbabel resets captions when the language starts\addto\captionsspanish{\renewcommand{\contentsname}{Contenido}}

Frequently Asked Questions

How do I change the language of a LaTeX document?

With pdfLaTeX, load babel with the language as an option: \usepackage[spanish]{babel} (plus \usepackage[T1]{fontenc} for accented letters). With XeLaTeX or LuaLaTeX, use polyglossia and \setdefaultlanguage{spanish}. Either way the language sets the captions (“Índice”, “Capítulo”), the date from \today, hyphenation and typographic rules.

How do I write LaTeX in Spanish?

Add \usepackage[T1]{fontenc} and \usepackage[spanish]{babel} to the preamble and type accents and ñ directly; UTF-8 input is the default since 2018. Add the es-tabla option if tables should be captioned “Tabla” instead of “Cuadro”, and \decimalpoint if you want 3.14 rather than 3,14 in math.

How do I write Arabic in LaTeX?

Compile with XeLaTeX, load polyglossia, declare \setotherlanguage{arabic} (or \setdefaultlanguage{arabic}) and give it a font that has Arabic glyphs with \newfontfamily\arabicfont[Script=Arabic]{Amiri}. Then write \textarabic{...} for a phrase or the Arabic environment for paragraphs; text runs right to left automatically.

Should I use babel or polyglossia?

Use babel with pdfLaTeX, which is still the default compiler on most platforms. With XeLaTeX, polyglossia is the traditional choice and handles right-to-left scripts well. Modern babel also works with XeLaTeX and LuaLaTeX and supports more languages, so on LuaLaTeX babel is the usual recommendation today.

How do I write Chinese or Japanese in LaTeX?

For Chinese, the simplest route is the ctexart class compiled with XeLaTeX: \documentclass{ctexart}, then type Chinese directly. For mixed documents, load xeCJK and set a CJK font with \setCJKmainfont. With pdfLaTeX, the CJKutf8 package and a \begin{CJK}{UTF8}{gbsn} environment work. Japanese is usually written with LuaLaTeX and luatexja.

How do I use two languages in one LaTeX document?

List all languages in the babel options, with the main one last: \usepackage[french,english]{babel}. Use \foreignlanguage{french}{...} for a phrase, the otherlanguage environment for a passage, and \selectlanguage{french} to switch for the rest of the document. Each switch changes hyphenation and, for \selectlanguage, captions and dates too.

Next Steps

Free LaTeX Tools

Write LaTeX in any language with AI

Octree has the full TeX Live with every language, font and compiler. Ask its AI to set up babel or polyglossia, fix right-to-left text or translate your captions, with the PDF compiled next to your code.

Try Octree Free →