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
.
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}{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{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}
.
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.
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.
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.