Multilingual typesetting on Overleaf using babel and fontspec
Contents
In September 2019 Overleaf upgraded to TeX Live 2018, meaning you can now use the babel
package with the XeLaTeX or LuaLaTeX compilers to assign fonts for typesetting specific languages or scripts—providing an alternative to using the polyglossia
package.
This article is a follow-up to accompany our earlier piece titled Multilingual typesetting on Overleaf using polyglossia and fontspec. Here, we show how to use the babel
package, via the \babelprovide
and \babelfont
commands, to reproduce examples contained in the previous article, which focussed on using polyglossia
.
Multiple languages/scripts in the same document with babel and \babelfont
To reproduce the first example in our earlier article, where the document’s main language is French but contains English, Russian and Thai text snippets, 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.
\usepackage[english,russian,main=french]{babel}
\babelprovide[import]{thai}
\babelfont{rm}[Language=Default]{FreeSerif}
\babelfont{sf}[Language=Default]{FreeSans}
\babelfont{tt}[Language=Default]{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{russian}{Спасибо.} Et plus de
texte en français!
Le Lorem Ipsum est le faux texte standard ...
\begin{otherlanguage}{english}
Lorem Ipsum is simply dummy text ...
\end{otherlanguage}
\begin{otherlanguage}{russian}
Lorem Ipsum - это текст-`\textsf{рыба}', часто используемый в
\texttt{печати} и вэб-дизайне. ...
\end{otherlanguage}
\begin{otherlanguage}{thai}
\foreignlanguage{english}{Lorem Ipsum} คือ เนื้อหาจำลองแบบเรียบๆ ที่ใช้กันในธุรกิจงานพิมพ์หรืองานเรียงพิมพ์
\end{{otherlanguage}}
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 \begin{otherlanguage}{language} ... \end{otherlanguage}
.
Mixing right-to-left (RTL) and left-to-right (LTR) languages
To typeset a document with Arabic as the main language we use \babelprovide[import,main]{arabic}
. We also need to ensure the document is typeset from right-to-left by default, which is achieved by passing-in the bidi=default
option when loading babel
:
\usepackage[english,bidi=default]{babel}
\babelprovide[import,main]{arabic}
\babelfont[arabic]{rm}{Amiri}
\begin{document}
ما هو \foreignlanguage{english}{differentiation}
\end{document}
See this example if you’d like to use the polyglossia
package instead.
Specifying fonts for specific languages
You can specify the font 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
\babelfont[english]{rm}{Free Chancery}
\babelfont[*cyrillic]{rm}{Charis SIL}
\babelfont[thai]{rm}{Garuda}
to use Free Chancery to typeset English text, Charis SIL to typeset all Cyrillic scripts (including Russian), and Garuda to typeset Thai text.
Here is another example of setting a font for a particluar script—Devanagari, which is used for Hindi and Sanskrit:
\usepackage[english]{babel}
%% Each \babelprovide can only be used for one language
\babelprovide[import]{hindi}
\babelprovide[import]{sanskrit}
\babelfont[*devanagari]{rm}{Lohit Devanagari}
...
Hindi: \foreignlanguage{hindi}{हिन्दी}
Sanskrit: \foreignlanguage{sanskrit}{संस्कृतम्}
See this example 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:
\usepackage[bidi=default]{babel}
\babelprovide[main,import]{hebrew}
\babelfont[hebrew]{rm}{Hadasim CLM}
\babelfont[hebrew]{sf}{Miriam CLM}
\usepackage{titlesec}
\titleformat{\section}{\Large\sffamily\bfseries}{\thesection}{1em}{}
...
\section{מבוא}
זוהי עובדה מבוססת שדעתו של הקורא תהיה מוסחת עלידי טקטס קריא כאשר הוא יביט בפריסתו.
See this example if you’d like to do this with the polyglossia
package instead.
Further Reading
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Using the Overleaf project menu
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides
- Guide to Overleaf’s premium features
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Matrices
- Fractions and Binomials
- Aligning equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
- Using the Symbol Palette in Overleaf
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections, equations and floats
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typesetting exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class