# Mix cyrillic characters and latin in XeLaTeX

I would like to mix cyrillic and latin characters in my document using XeLaTeX. It compiles, but the cyrillic characters do not show up in the pdf. Also, I would like to use the default LaTeX font for the latin characters and use another font for the cyrillic ones, if necessary.

\documentclass{article}

\usepackage{fontspec}
\usepackage[T1,T2A]{fontenc}

\usepackage[russian,english]{babel}
\begin{document}
Latin first.

\fontencoding{T2A}\selectfont Математические формулы
\end{document}

• Welcome, why are you fiddling with font encodings? Remove everything font related which is not fontspec. Jul 7, 2018 at 5:49
• Even then the same thing happens. Jul 7, 2018 at 5:52
• \usepackage{libertine} for example. But there are dozens of questions around already. Jul 7, 2018 at 5:54
• I have checked many of them, none of them answer my question. Yes, libertine shows the cyrillic characters, but changes the latin ones which I want to preserve in original. Thanks in any case. Jul 7, 2018 at 5:58
• do not use 8-bit fonts such as T1 or T2A with xelatex. If you use \usepackage[T1,T2A]{fontenc} then all hyphenation will be wrong. Jul 7, 2018 at 7:31

You got a polyglossia answer, so here is a babel solution. These features are fairly new (the babel docs say version 3.15).

\documentclass{article}
\usepackage{fontspec}
\usepackage[russian,english]{babel}

\babelfont{rm}[
Ligatures=TeX,
SmallCapsFont={Latin Modern Roman Caps}]%
{Latin Modern Roman}
\babelfont[russian]{rm}[
Ligatures={Common, TeX},
Scale=MatchUppercase]%
{Libertinus Serif}

\begin{document}
Mathematical formulas

\begin{otherlanguage}{russian}
Математические формулы
\end{otherlanguage}

Mathematical formulae

\foreignlanguage{russian}{Математические формулы}
\end{document}


Note the difference in the language-switching interface (\begin{otherlanguage}{<language>}...\end{otherlanguage} and \foreignlanguage{<language>} vs \begin{<language>}...\end{<language>} and \text<language>).

There is also no \setmainfont here, even the default language is set up with \babelfont.

Maybe a few words to what is going on here. As mentioned by David Carlisle in the comments, fontenc (and its encoding switches) should not be used with XeLaTeX or LuaLaTeX. But even if you remove it you don't see what you expect. The font your document uses with the setup from the question does not have characters for Cyrillic, so these characters are just discarded.

The prettiest solution would probably be to pick a font that supports all scripts you need (so at least Cyrillic and Latin) and then use the same font for the entire document. That makes the appearance more uniform and harmonic.

Davislor's answer and this one here both show a way to select the font depending on the selected language in the document. It would apparently also be possible to try to change font depending on Unicode blocks, see How can I use ucharclasses to change the font for a special script and then restore to what it was before?, In LuaTex is it possible to change font/language according to the script/glyphs used?, XeTeX, change font usage when meeting greek characters (Sabon Linotype / Sabon Greek), Change XeTeX fonts automatically depending on Unicode blocks.

• You don't like the Common ligatures? ;) Jul 7, 2018 at 8:20
• @Davislor That just snuck in from somewhere. I hadn't given it much though, but I do like my --s to turn into en-dashes, so I would probably keep it. Jul 7, 2018 at 8:25
• Ligatures={Common, TeX} works, as I'm sure you know. Or {Common, Rare, Historic, TeX} if the font supports it. Jul 7, 2018 at 8:27
• @Davislor I didn't actually, thank you. But I'm wondering what I'm missing by declaring only Ligatures=TeX. A short test with the most common ligatures seemed to give the same results as Ligatures={Common, TeX}. Jul 7, 2018 at 8:45
• @Davislor If I understand correctly, babel actually handles Script and Language itself, so that should not be needed (and is discouraged) when using \babelfont. I used Language=Default so silence the warning about Russian not being available with Libertinus, but I figured it would be better to remove it. Jul 7, 2018 at 8:52

Use polyglossia to get multilingual text, and set \russianfont.

Use \begin{russian} for long passages in Russian and \textrussian{} for short ones. If the document is primarily in Russian, \setdefaultlanguage{russian}.

\documentclass[varwidth, preview]{standalone}
\usepackage{fontspec}
\usepackage{polyglossia}

\setmainfont{Latin Modern Roman}
\defaultfontfeatures{Scale=MatchUppercase}
\newfontfamily\russianfont{Libertinus Serif}[
Script=Cyrillic,
Language=Russian]

\setdefaultlanguage{english}
\setotherlanguage{russian}

\begin{document}

Latin first.  \textrussian{Математические формулы}

\end{document}

• I get an error when processing the above file: fontspec warning: "language-not-exist" * Language 'Russian' not available for font 'Libertinus Serif' with script * 'Cyrillic'. * 'Default' language used instead' Feb 21, 2019 at 12:06
• @PauloNey That warning message is harmless, but you can suppress it by deleting Language=Russian within \newfontfamily\russianfont. There are, however, some fonts for which selecting Russian or Bulgarian matters. Feb 22, 2019 at 4:18

My idea is to combine the polyglossia package, and the newcomputermodern package which supplies Russian letters with different shapes and weights quite consistent with Computer Modern fonts. You could use the following codes.

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{russian}
\newfontfamily\russianfont[Script=Cyrillic,Language=Russian,
ItalicFont={NewCM10-Italic.otf}, BoldFont={NewCM10-Bold.otf},
BoldItalicFont={NewCM10-BoldItalic.otf}]{NewCM10-Regular.otf}
\newfontfamily\russianfontsf[Script=Cyrillic,Language=Russian,
ItalicFont={NewCMSans10-Oblique.otf}, BoldFont={NewCMSans10-Bold.otf},
BoldItalicFont={NewCMSans10-BoldOblique.otf}]{NewCMSans10-Regular.otf}
\newfontfamily\russianfonttt[Script=Cyrillic,Language=Russian,
ItalicFont={NewCMMono10-Italic.otf}, BoldFont={NewCMMono10-Bold.otf},
BoldItalicFont={NewCMMono10-BoldOblique.otf}]{NewCMMono10-Regular.otf}

\begin{document}
Mathematical formulas

{\itshape\textrussian{Математические формулы}}

Mathematical formulae

{\bfseries\textrussian{Математические формулы}}

Mathematical formulas

{\itshape\bfseries\textrussian{Математические формулы}}

Mathematical formulae

{\sffamily\textrussian{Математические формулы}}

Mathematical formulas

{\ttfamily\textrussian{Математические формулы}}

\end{document}


Note that you needn't install these otf fonts on your computer which have been included in the newcomputermodern package. Its compiled result is as follows.

Also, if you want the main(English) language to be also New Computer Modern fonts which are almost the same as Computer Modern fonts, the inputs would be easier and you could use the following codes.

\documentclass{article}
\usepackage[regular]{newcomputermodern}

\begin{document}
Mathematical formulas

{\itshape Математические формулы}

Mathematical formulae

{\bfseries Математические формулы}

Mathematical formulas

{\itshape\bfseries Математические формулы}

Mathematical formulae

{\sffamily Математические формулы}

Mathematical formulas

{\ttfamily Математические формулы}

\end{document}


\usepackage[regular]{newcomputermodern} could also be replaced by \usepackage[olddefault]{fontsetup}. Its compiled result is the same as above.

By the way, the newcomputermodern` package also includes text letters in other language such as greek and so on, and the way to invoke is similar as above.