> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/languages/02-multilingual-typesetting-on-overleaf-using-babel-and-fontspec.md).

# Multilingual typesetting on Overleaf using babel and fontspec

## Introduction

This article is a follow-up to our earlier piece titled [Multilingual typesetting on Overleaf using polyglossia and fontspec](/latex/languages/01-multilingual-typesetting-on-overleaf-using-polyglossia-and-fontspec.md). Here, we show how to use the [`babel` package](https://ctan.org/pkg/babel), via its `\babelprovide` and `\babelfont` commands, to reproduce examples contained in the previous article, which focussed on [`polyglossia`](https://ctan.org/pkg/polyglossia?lang=en).

This article is *not* meant to be a comprehensive introduction to the `babel` package, which is feature-rich and highly customizable with numerous options for typesetting different languages. In addition, babel possesses features which are not present in polyglossia—for further details, please refer to [`babel`’s documentation](https://mirror.apps.cam.ac.uk/pub/tex-archive/macros/latex/required/babel/base/babel.pdf).

## Multiple languages/scripts in the same document with babel and \babelfont

To reproduce the [first example in our article on `polyglossia`](/latex/languages/01-multilingual-typesetting-on-overleaf-using-polyglossia-and-fontspec.md#french-english-russian-thai), where the document’s primary language is French but contains text in English, Russian and Thai, you can now load `babel` for text in English, Russian and French but use the `\babelprovide` command to load support for Thai. We use the `\babelfont` command to set the document’s fonts: FreeSerif, FreeSans and FreeMono which provide sufficient support for the Latin, Cyrillic and Thai scripts.

```latex
\documentclass[12pt]{article}
\usepackage{geometry}  % to use a small page size
\geometry{margin=4cm,b5paper}
\usepackage[english,russian,french]{babel}
\babelprovide[import]{thai}
\babelfont{rm}{FreeSerif}
\babelfont{sf}{FreeSans}
\babelfont{tt}{FreeMono}
\begin{document}
\begin{abstract}
Le Lorem Ipsum est simplement du faux texte employé dans la composition et la mise en page avant impression.
\end{abstract}

Merci. \foreignlanguage{english}{Thank you.} \foreignlanguage{thai}{ขอบคุณ} \foreignlanguage{russian}{Спасибо.} Et plus de
texte en français!

Le Lorem Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen de polices de texte.

\begin{otherlanguage}{english}
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \end{otherlanguage}

\begin{otherlanguage}{russian}
Lorem Ipsum - это текст-`\textsf{рыба}', часто используемый в \texttt{печати} и вэб-дизайне. Lorem Ipsum является стандартной ``рыбой'' для текстов на латинице с начала XVI века. В то время некий безымянный печатник создал большую коллекцию размеров и форм шрифтов, используя Lorem Ipsum для распечатки образцов. Lorem Ipsum не только успешно пережил без заметных изменений пять веков, но и перешагнул в электронный дизайн. \end{otherlanguage}

\begin{otherlanguage}{thai}
\foreignlanguage{english}{Lorem Ipsum} คือ เนื้อหาจำลองแบบเรียบๆ ที่ใช้กันในธุรกิจงานพิมพ์หรืองานเรียงพิมพ์
\end{otherlanguage}
\end{document}
```

[Open this XeLaTeX example in Overleaf.](<https://www.overleaf.com/docs?engine=xelatex\&snip_name=Example+using+the+babel+package\&snip=\documentclass\[12pt]{article}&#xA;\usepackage{geometry}++%+to+use+a+small+page+size&#xA;\geometry{margin=4cm,b5paper}&#xA;\usepackage\[english,russian,french]{babel}&#xA;\babelprovide\[import]{thai}&#xA;\babelfont{rm}{FreeSerif}&#xA;\babelfont{sf}{FreeSans}&#xA;\babelfont{tt}{FreeMono}&#xA;\begin{document}&#xA;\begin{abstract}&#xA;Le+Lorem+Ipsum+est+simplement+du+faux+texte+employé+dans+la+composition+et+la+mise+en+page+avant+impression.&#xA;\end{abstract}&#xA;+&#xA;Merci.+\foreignlanguage{english}{Thank+you.}+\foreignlanguage{thai}{ขอบคุณ}+\foreignlanguage{russian}{Спасибо.}+Et+plus+de&#xA;texte+en+français!&#xA;+&#xA;Le+Lorem+Ipsum+est+le+faux+texte+standard+de+l'imprimerie+depuis+les+années+1500,+quand+un+imprimeur+anonyme+assembla+ensemble+des+morceaux+de+texte+pour+réaliser+un+livre+spécimen+de+polices+de+texte.&#xA;&#xA;\begin{otherlanguage}{english}&#xA;Lorem+Ipsum+is+simply+dummy+text+of+the+printing+and+typesetting+industry.+Lorem+Ipsum+has+been+the+industry’s+standard+dummy+text+ever+since+the+1500s,+when+an+unknown+printer+took+a+galley+of+type+and+scrambled+it+to+make+a+type+specimen+book.+&#xA;&#xA;It+has+survived+not+only+five+centuries,+but+also+the+leap+into+electronic+typesetting,+remaining+essentially+unchanged.+\end{otherlanguage}&#xA;+&#xA;\begin{otherlanguage}{russian}&#xA;Lorem+Ipsum+-+это+текст-`\textsf{рыба}',+часто+используемый+в+\texttt{печати}+и+вэб-дизайне.+Lorem+Ipsum+является+стандартной+``рыбой''+для+текстов+на+латинице+с+начала+XVI+века.+В+то+время+некий+безымянный+печатник+создал+большую+коллекцию+размеров+и+форм+шрифтов,+используя+Lorem+Ipsum+для+распечатки+образцов.+Lorem+Ipsum+не+только+успешно+пережил+без+заметных+изменений+пять+веков,+но+и+перешагнул+в+электронный+дизайн.+\end{otherlanguage}&#xA;+&#xA;\begin{otherlanguage}{thai}&#xA;\foreignlanguage{english}{Lorem+Ipsum}+คือ+เนื้อหาจำลองแบบเรียบๆ+ที่ใช้กันในธุรกิจงานพิมพ์หรืองานเรียงพิมพ์&#xA;\end{otherlanguage}&#xA;\end{document}>)

This example produces the following output:

![An example of the babel package on Overleaf](/files/MtD9K2ycxTLVNl3lCN7c)

By default, the last language name passed as an option to `babel` becomes the document’s main language—in the above example, it is French. Because the document’s main language is set to French, it will, by default, use French typesetting conventions: this would include French hyphenation patterns, punctuation and some automatic keywords—such as Résumé instead of Abstract. Short text snippets in a different language are inserted with `\foreignlanguage{language}{...}`. Longer paragraphs of foreign language text are inserted with

```latex
\begin{otherlanguage}{language} ... \end{otherlanguage}
```

Within a list of language options the `main` key can be used to select any one of them as the document’s main language, *not* just the last one in the list; for example, this would set English as the main language instead of French:

```latex
\usepackage[main=english,russian,french]{babel}
```

### Notes on fontspec package warnings

With some fonts, you may get compile warnings such as these:

![Some font warnings produced using the babel package](/files/kOO6eDl8T4QGw7k6rPpL)

These messages highlight issues that are “usually fine” or note font-related default settings that are “not always wrong”. If you carefully check your document for font-related typesetting problems and all seems well, then you *may* be able to ignore those messages. Even if your document is problem-free, but you’d prefer to avoid (prevent) those warnings, you can try using different fonts.

Other options to avoid (prevent) these warnings include:

* adding the `fontspec` options of `Language=Default` and `Script=Default`:

```latex
\babelfont{rm}[Language=Default,Script=Default]{FreeSerif}
\babelfont{sf}[Language=Default,Script=Default]{FreeSans}
\babelfont{tt}[Language=Default,Script=Default]{FreeMono}
```

**Note:** Although this removes the warning messages, these settings are not ideal because they can potentially break font features specific to some languages. See [this discussion](https://tex.stackexchange.com/questions/478487/avoid-fontspec-warning-with-babel/478541#comment1208608_478505) for further information.

* adding `\PassOptionsToPackage{silent}{fontspec}` to your document preable:

```latex
\documentclass{article}
\usepackage[english,russian,french]{babel}
\PassOptionsToPackage{silent}{fontspec}
\babelprovide[import]{thai}
\babelfont{rm}{FreeSerif}
\babelfont{sf}{FreeSans}
\babelfont{tt}{FreeMono}
\begin{document}
...
\end{document}
```

This silences the `fontspec` package, but it is a risky option in case `fontspec` later needs to warn you of other, more serious, problems.

For more information, see [discussions on tex.stackexchange](https://tex.stackexchange.com/questions/478487/avoid-fontspec-warning-with-babel), in particular [this answer](https://tex.stackexchange.com/a/478541).

## Mixing right-to-left (RTL) and left-to-right (LTR) languages

To typeset a document with Arabic as the main language we can use

```latex
\babelprovide[import,main]{arabic}
```

A document whose *main* language is Arabic but contains text fragments in LTR languages, such as English, has the following typesetting requirements:

* it has to be typeset from right-to-left (by default);
* arbitrary mixtures of RTL and LTR text fragments should be typeset correctly—usually via an implementation of the [Unicode Bidirectional Algorithm](https://unicode.org/reports/tr9/).

Both objectives are achieved by providing `babel` with a suitable `bidi` option, whose value depends on the LaTeX compiler you are using:

* for LuaLaTeX: use `bidi=basic`;
* for pdfLaTeX and XeLaTeX use `bidi=default`.
* **Note**: For further detail please consult [`babel`’s documentation](https://mirror.apps.cam.ac.uk/pub/tex-archive/macros/latex/required/babel/base/babel.pdf) which lists additional values for the `bidi` option and provides a range of helpful examples.

Here is a small XeLaTeX example using `bidi=default`:

```latex
\documentclass{article}
\usepackage[english,bidi=default]{babel}
\babelprovide[import,main]{arabic}
\babelfont[arabic]{rm}{Amiri}
\begin{document}
ما هو \foreignlanguage{english}{differentiation}
\end{document}
```

[Open this XeLaTeX example in Overleaf.](https://www.overleaf.com/docs?engine=xelatex\&snip_name=Bidirectional+text+typesetting+with+babel\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Benglish%2Cbidi%3Ddefault%5D%7Bbabel%7D%0A%5Cbabelprovide%5Bimport%2Cmain%5D%7Barabic%7D%0A%5Cbabelfont%5Barabic%5D%7Brm%7D%7BAmiri%7D%0A%5Cbegin%7Bdocument%7D%0A%D9%85%D8%A7+%D9%87%D9%88+%5Cforeignlanguage%7Benglish%7D%7Bdifferentiation%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![An example of bidirectional typesetting using XeLaTeX and the babel package on Overleaf](/files/V2jB1fM2hKUgfG1gtmWT)

See [this example](/latex/languages/01-multilingual-typesetting-on-overleaf-using-polyglossia-and-fontspec.md#rtl) if you’d like to use the `polyglossia` package instead.

If you need to typeset RTL languages and/or bidirectional text, the LuaLaTeX compiler is strongly recommended because it provides the most comprehensive support for complex-script languages and bidirectional typesetting.

* **Tip**: A comprehensive example of typesetting Arabic, using LuaLaTeX and `babel`, can be found in the [babel’s github repository](https://github.com/latex3/babel/blob/main/samples/lua-arabic.tex).

The following example uses an extract of text taken from [`babel`’s github repository](https://github.com/latex3/babel/blob/main/samples/lua-arabic.tex).

```latex
% Arabic text in this example is from
% https://github.com/latex3/babel/blob/main/samples/lua-arabic.tex
\documentclass{article}
\usepackage[english,bidi=basic]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{FreeSerif}
\babelfont{sf}{FreeSans}
\babelfont{tt}{FreeMono}
\begin{document}
الكهرمان اسمه باليونانية الإيلقطرون[3] (معرب ἤλεκτρον إيلكترون أي ذو
البريق، ومنه الإلكترون عند الفيزيائيين، وعليه تسمية الكهرباء في
الفارسية برق)، واشتق منه اسم فاعليتيه فسمي إلكترسمس (ηλεκτρ‌ισμός)
للدلالة على الكهرباء. أما باللاتينية فالكلمة للكهرباء هي إيلكترستاس
(ēlectricitās)، وهي مشتقة من إيلكتركس (ēlectricus) أي شبيه الكهرمان.
\end{document}
```

[Open this LuaLaTeX example in Overleaf.](<https://www.overleaf.com/docs?engine=lualatex\&snip_name=Bidirectional+text+typesetting+with+babel\&snip=%+Arabic+text+in+this+example+is+from+&#xA;%+https://github.com/latex3/babel/blob/main/samples/lua-arabic.tex&#xA;\documentclass{article}&#xA;\usepackage\[english,bidi=basic]{babel}&#xA;\babelprovide\[import,main]{arabic}&#xA;\babelfont{rm}{FreeSerif}&#xA;\babelfont{sf}{FreeSans}&#xA;\babelfont{tt}{FreeMono}&#xA;\begin{document}&#xA;الكهرمان+اسمه+باليونانية+الإيلقطرون\[3]+(معرب+ἤλεκτρον+إيلكترون+أي+ذو&#xA;البريق،+ومنه+الإلكترون+عند+الفيزيائيين،+وعليه+تسمية+الكهرباء+في&#xA;الفارسية+برق)،+واشتق+منه+اسم+فاعليتيه+فسمي+إلكترسمس+(ηλεκτρ‌ισμός)&#xA;للدلالة+على+الكهرباء.+أما+باللاتينية+فالكلمة+للكهرباء+هي+إيلكترستاس&#xA;(ēlectricitās)،+وهي+مشتقة+من+إيلكتركس+(ēlectricus)+أي+شبيه+الكهرمان.&#xA;\end{document}>)

This example produces the following output:

![An example of bidirectional typesetting using the babel package on Overleaf](/files/SwaFop5FOMK9MejK4ViP)

## Specifying fonts for specific languages

You can specify the fonts used for different languages by adding the language name or the script name, preceded by an \*, as an option to `\babelfont`. In our French—English—Russian—Thai example, you can add

```latex
\babelfont[english]{rm}{Chancery Uralic}
\babelfont[*cyrillic]{rm}{Charis SIL}
\babelfont[thai]{rm}{Garuda}
```

to use Chancery Uralic to typeset English text, Charis SIL to typeset all Cyrillic scripts (including Russian), and Garuda to typeset Thai text.

* **Please note**: We are not suggesting the next example provides a typographically harmonious combination of type styles, it merely shows how to configure and use fonts of your choice.

```latex
\documentclass[12pt]{article}
\usepackage{geometry} % to use a small page size
\geometry{margin=4cm,b5paper}
\usepackage[english,russian,main=french]{babel}
\babelprovide[import]{thai}

%% When all the \babelfont lines are uncommented, we can show that e.g. \babelfont[english], [*cyrillic] etc really do override the default \babelfont{rm} for English, Cyrillic.
\babelfont{rm}[Language=Default]{FreeSerif}
\babelfont{sf}[Language=Default]{FreeSans}
\babelfont{tt}[Language=Default]{FreeMono}

\babelfont[english]{rm}{Chancery Uralic}
\babelfont[*cyrillic]{rm}{Charis SIL}
\babelfont[thai]{rm}{Garuda}
\begin{document}
\begin{abstract}
Le Lorem Ipsum est simplement du faux texte employé dans la composition et la mise en page avant impression.
\end{abstract}

Merci. \foreignlanguage{english}{Thank you.} \foreignlanguage{thai}{ขอบคุณ} \foreignlanguage{russian}{Спасибо.} Et plus de
texte en français!

Le Lorem Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen de polices de texte.

\begin{otherlanguage}{english}
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \end{otherlanguage}

\begin{otherlanguage}{russian}
Lorem Ipsum - это текст-`\textsf{рыба}', часто используемый в \texttt{печати} и вэб-дизайне. Lorem Ipsum является стандартной ``рыбой'' для текстов на латинице с начала XVI века. В то время некий безымянный печатник создал большую коллекцию размеров и форм шрифтов, используя Lorem Ipsum для распечатки образцов. Lorem Ipsum не только успешно пережил без заметных изменений пять веков, но и перешагнул в электронный дизайн. \end{otherlanguage}

\begin{otherlanguage}{thai}
\foreignlanguage{english}{Lorem Ipsum} คือ เนื้อหาจำลองแบบเรียบๆ ที่ใช้กันในธุรกิจงานพิมพ์หรืองานเรียงพิมพ์
\end{otherlanguage}
\end{document}
```

Open this XeLaTeX example in Overleaf.

This example produces the following output:

![An Overlreaf example of configuring the babel package to use different fonts for specific languages](/files/KTY3rSXQ6FBZeodp7pSb)

Here is another example of specifying a font for a particular script—Devanagari, which is used for Hindi and Sanskrit:

```latex
\documentclass[12pt]{article}
\usepackage[english]{babel}
%% Each \babelprovide can only be used for one language
\babelprovide[import]{hindi}
\babelprovide[import]{sanskrit}
\babelfont[*devanagari]{rm}{Lohit Devanagari}
\begin{document}
Hindi: \foreignlanguage{hindi}{हिन्दी}

Sanskrit: \foreignlanguage{sanskrit}{संस्कृतम्}
\end{document}
```

[Open this LuaLaTeX example in Overleaf.](https://www.overleaf.com/docs?engine=lualatex\&snip_name=Overleaf+example+typesetting+Hindi+and+Sanskrit+using+the+babel+package\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%5Benglish%5D%7Bbabel%7D%0A%25%25+Each+%5Cbabelprovide+can+only+be+used+for+one+language%0A%5Cbabelprovide%5Bimport%5D%7Bhindi%7D%0A%5Cbabelprovide%5Bimport%5D%7Bsanskrit%7D%0A%5Cbabelfont%5B%2Adevanagari%5D%7Brm%7D%7BLohit+Devanagari%7D%0A%5Cbegin%7Bdocument%7D%0AHindi%3A+%5Cforeignlanguage%7Bhindi%7D%7B%E0%A4%B9%E0%A4%BF%E0%A4%A8%E0%A5%8D%E0%A4%A6%E0%A5%80%7D%0A%0ASanskrit%3A+%5Cforeignlanguage%7Bsanskrit%7D%7B%E0%A4%B8%E0%A4%82%E0%A4%B8%E0%A5%8D%E0%A4%95%E0%A5%83%E0%A4%A4%E0%A4%AE%E0%A5%8D%7D%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![An Overlreaf example typesetting Devanagari scripts: Hindi and Sanskrit](/files/WKUn0YlfFCZ5oo2AIEEn)

See [this example](/latex/languages/01-multilingual-typesetting-on-overleaf-using-polyglossia-and-fontspec.md#devnag) if you’d like to do this with the `polyglossia` package instead.

## Defining other font families

Recall that you can set typefaces for different languages and families. In the following example we explicitly set a sans serif font for Hebrew because we would like to use sans serif for section headers:

```latex
\documentclass[12pt]{article}
\usepackage{geometry} % to use a small page size
\geometry{margin=4cm,b5paper}
\usepackage[bidi=basic]{babel}
\babelprovide[main,import]{hebrew}
\babelfont[hebrew]{rm}{Hadasim CLM}
\babelfont[hebrew]{sf}{Miriam CLM}
\usepackage{titlesec}
\titleformat{\section}{\Large\sffamily\bfseries}{\thesection}{1em}{}
\begin{document}
\section{מבוא}

זוהי עובדה מבוססת שדעתו של הקורא תהיה מוסחת עלידי טקטס קריא כאשר הוא יביט בפריסתו.
\end{document}
```

[Open this LuaLaTeX example in Overleaf.](https://www.overleaf.com/docs?engine=lualatex\&snip_name=Overleaf+example+typesetting+Hebrew+using+the+babel+package\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%7Bgeometry%7D+%25+to+use+a+small+page+size%0A%5Cgeometry%7Bmargin%3D4cm%2Cb5paper%7D%0A%5Cusepackage%5Bbidi%3Dbasic%5D%7Bbabel%7D%0A%5Cbabelprovide%5Bmain%2Cimport%5D%7Bhebrew%7D%0A%5Cbabelfont%5Bhebrew%5D%7Brm%7D%7BHadasim+CLM%7D%0A%5Cbabelfont%5Bhebrew%5D%7Bsf%7D%7BMiriam+CLM%7D%0A%5Cusepackage%7Btitlesec%7D%0A%5Ctitleformat%7B%5Csection%7D%7B%5CLarge%5Csffamily%5Cbfseries%7D%7B%5Cthesection%7D%7B1em%7D%7B%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csection%7B%D7%9E%D7%91%D7%95%D7%90%7D%0A%0A%D7%96%D7%95%D7%94%D7%99+%D7%A2%D7%95%D7%91%D7%93%D7%94+%D7%9E%D7%91%D7%95%D7%A1%D7%A1%D7%AA+%D7%A9%D7%93%D7%A2%D7%AA%D7%95+%D7%A9%D7%9C+%D7%94%D7%A7%D7%95%D7%A8%D7%90+%D7%AA%D7%94%D7%99%D7%94+%D7%9E%D7%95%D7%A1%D7%97%D7%AA+%D7%A2%D7%9C%D7%99%D7%93%D7%99+%D7%98%D7%A7%D7%98%D7%A1+%D7%A7%D7%A8%D7%99%D7%90+%D7%9B%D7%90%D7%A9%D7%A8+%D7%94%D7%95%D7%90+%D7%99%D7%91%D7%99%D7%98+%D7%91%D7%A4%D7%A8%D7%99%D7%A1%D7%AA%D7%95.%0A%5Cend%7Bdocument%7D)

This example produces the following output:

![An Overleaf example typesetting Hebrew using the babel package](/files/T2pi1xrwtai8TC5G8mzG)

## Further Reading

* [Multilingual typesetting on Overleaf using polyglossia and fontspec](/latex/languages/01-multilingual-typesetting-on-overleaf-using-polyglossia-and-fontspec.md)
* [`babel` documentation on CTAN](https://mirror.apps.cam.ac.uk/pub/tex-archive/macros/latex/required/babel/base/babel.pdf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/languages/02-multilingual-typesetting-on-overleaf-using-babel-and-fontspec.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
