What are different ways to use Cyrillic in (La)TeX? What are their pros and cons?
7 Answers
inputenc
+ babel
Usage
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
Pros
Standard — works with any LaTeX installation. One can use any encoding in .tex files. Works fine with hyperref
. It works with xetex
and luatex
, too, provided inputenc
is not loaded and the encoding is UTF-8.
Cons
With pdftex
, Cyrillic letters become active symbols — so one can neither define commands with Cyrillic names nor use them in arguments of \label
, \cite
etc. Cyrillic letters in .aux and .toc files become unreadable.
Note
If you get this error: Unknown option 'russian'. Either you misspelled it or the language definition file francais.ldf was not found try installing the texlive-lang-cyrillic
package. (source)
-
Cyrillics is not active any more if xetex or luatex is used to compile your document. See ctan.org/pkg/russian. Commented Apr 15, 2013 at 8:24
-
1The huge advantage of this method is the vast range of font shapes present in the CMU font. The drawback... one you get used to it, you will be disappointed by the fact that there is virtually no alternative to this mega-font except for the
paratype
package (T2A is poorly supported as of today). Some users might install the “Literaturnaya” typeface, but Computer Modern will become your daily bread. IMHO, it is has a very aristocratic look. Commented Jan 24, 2016 at 14:25 -
Another possible con is the treatment of diacritics. Try for example to enter Его́р Тиму́рович Гайда́р. For me it break the rendering of all Cyrillic text in my document like the economy of the 90s. Without accents like "´" on vowels, all is well again in latex. Though not often used in Russian, for us non-native speakers, accents are sometimes crucial. I, for example, always thought his name was Га́йдар :/– nJGLCommented Mar 22, 2019 at 20:32
-
fyi: this turned a bunch of things into Russian that I didn't want (auto-filled content such as "References" and "List of Figures"). Egreg's expansion below fixed it. Commented Mar 14, 2020 at 21:13
For multilingual texts with pdflatex
(as opposed to using the xelatex
or lualatex
engines), the best option is to use the UTF-8 encoding for the input and babel
:
\documentclass{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian,english]{babel}
\begin{document}
Text in English
\begin{otherlanguage*}{russian}
Текст на русском языке
\end{otherlanguage*}
A word and another \foreignlanguage{russian}{слово}
\end{document}
There are a number of fonts available in the T2A encoding for pdflatex
:
For a wider choice, XeLaTeX or LuaLaTeX are best.
-
1It appears that passing option
T2A
tofontenc
is optional, this is arranged byrussian
babel option already. Mentioning this because it can be useful to know for automatically generated document which only useT1
a priori.– user4686Commented Oct 10, 2017 at 11:41
XeLaTeX
Usage
\documentclass{article}
\usepackage{fontspec} % loaded by polyglossia, but included here for transparency
\usepackage{polyglossia}
\setmainlanguage{russian}
\setotherlanguage{english}
% XeLaTeX can use any font installed in your system fonts folder
% Linux Libertine in the next line can be replaced with any
% OpenType or TrueType font that supports the Cyrillic script.
\newfontfamily\russianfont[Script=Cyrillic]{Linux Libertine}
\begin{document}
Привет
\begin{english}
Hello!
\end{english}
\end{document}
Compile with xelatex
.
Pros
Works out of the box in fresh TeX distributions. Cyrillic letters can be used freely in control sequence names, labels, etc.
Cons
One needs a pretty modern TeX distribution. (What else?)
-
Computer Modern Unicode is a far lesser deviation from the default fonts than Linux Libertine. Is there any reason to not to use it in this example? Commented Mar 8, 2011 at 13:22
-
Until your comment, I'd never heard of this font. I used Linux Libertine because it seems to be widely known. Since xelatex can use any font installed in your system, the actual font doesn't matter. I've added a comment to the code to this effect. Commented Mar 22, 2011 at 15:42
-
With babel 3.9, there is no need to use polyglossia instead of babel. At least, I don't know any reason for that. Commented Apr 15, 2013 at 8:21
Mixing Cyrillic and Latin letters
The basic idea is to use babel
and inputenc
(like inputenc+babel). Your document looks like:
\documentclass{article}
\usepackage[OT2, T1]{fontenc}
\usepackage[russian, english]{babel}
\begin{document}
\foreignlanguage{russian}{Druzhba} means friendship.
\end{document}
Especially important is OT2
-encoding and russian
as option to babel
. The command \foreignlanguage
allows you to switch between English and Russian.
Pros
- You don't need a Cyrillic keyboard.
- Nearly every LaTeX system has
OT2
. babel
also offers specific names e.g. for the table of contents (Содержание), table of ..
Cons
- Hyphenation does not work perfect.
- Using
OT2
encoding is like a poor man's alternative toT2A
Some time ago I wrote a blog post in German: Kyrillischen Text mit LaTeX setzen
-
Walter Schmidt's document (in German), mentioned in the blog posting, has a table of the OT2 input encoding, which I've not been able to find anywhere else: home.vr-web.de/was/x/pmcyr.pdf– ptomatoCommented Aug 10, 2010 at 10:31
-
T2A encoding is default for russian document. OT2 is considered to be outdated encoding. I could hardly understand why you are recommending OT2. Perhaps, because I do have russian keyborad, :). Commented Oct 8, 2011 at 12:51
-
I tried this and what I got is "Package babel Error: No Cyrillic encoding definition files were found." :( Commented Feb 8, 2013 at 10:14
-
@IgorKotelnikov: This method (using OT2) was the only one successful in getting some of the non-base-256 cyrillic letters to get displayed in LaTeX. Very good!– AlexCommented Mar 8, 2015 at 4:21
Using UTF-8
If you're using UTF-8, you have a Russian keyboard and you want to type only Russian texts, the best would be:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A]{fontenc}
\begin{document}
ЛаТеХ
\end{document}
This way you don't have to change your behaviour. Typing LaTeX texts is as easy as typing other texts. Usually you also have correct hyphenation patterns, so you can use the full feature set of LaTeX. :-)
-
3Isn't it just a method "inputenc + babel" (with all it cons) but without working hyphenation? Commented Aug 2, 2010 at 20:24
-
This works also for bilangual english-russian docs. So your statement that it works only for russian text seemed to be suspicious. Commented Oct 8, 2011 at 12:56
-
I tried this and what I got is " Package fontenc Error: Encoding file `t2aenc.def' not found. (fontenc) You might have misspelt the name of the encoding." Commented Feb 8, 2013 at 10:15
-
Problem: words in Cyrillic aren't searchable (in Cyrillic) if you typeset them using control sequences. Solution: this answer.– user93292Commented May 27, 2017 at 15:09
Cherepanov's russlh
Usage
%&latex --tcx=koi2t2
\usepackage{russlh}
(Can be downloaded e.g. from http://www.mccme.ru/free-books/p_cher.htm.)
Pros
Cyrillic letters are \catcode
'd to 11
("letter"); thus, they can be used freely in control sequence names, labels, etc. In text files written by LaTeX (.toc, .aux, .idx, etc.) Russian letters are recoded back to their initial form, which makes these files readable and simplifies the processing of .idx files.
Cons
One has to (download and) use a non-standard package. Doesn't work with hyperref
(at least not with the current version).
-
Any reason to use one of many-many outdated medhods of russification superseeded by official babel? Commented Oct 8, 2011 at 12:53
-
3@Igor Well, one typical scenario is that one needs to use a complicated .sty file with Cyrillic control sequence names / some .tex file with a lot of Cyrillic labels. Commented Oct 8, 2011 at 15:43
LuaLaTeX
Another modern option for Cyrillics is LuaLaTeX (with babel
or polyglossia
, though polyglossia
still has an annoying bug and forgets to switch font family/shape sometimes).
Usage
\documentclass{article}
\usepackage{fontspec}
% The default Latin Modern font family doesn't contain Cyrillics,
% so load Computer Modern Unicode instead
\setmainfont{CMU Serif}[Ligatures=TeX]
\usepackage[english,russian]{babel}
\begin{document}
Привет
{\selectlanguage{english}%
Hello!
}
\end{document}
Pros
LuaLaTeX can use any TTF or OTF font without any additional work like creating TFM an virtual fonts for pdfLaTeX.
To use a font by its name, one can just drop it into her ~/texmf/
tree and doesn't have to install it as a system font.
Since LuaTeX is a fully unicode-aware engine, one can freely mix languages, with only requirement that all the necessary glyphs are present in utilized fonts.
Auxiliary files like .aux
, .toc
, .idx
etc. are human readable in contrast to pdfLaTeX (with inputenc). It helps with debugging index or PDF bookmarks.
Cons
Requires modern TeX distribution. For example, limits positioning for slanted math operators (like integrals) was fixed only in version 1.0 (TeXlive 2016 has 0.95).
-
-
As far as I can see, the default font used by LuaLaTeX doesn't have Cyrillic letters. So yes, it does change the font, but it necessary. Commented Jun 22, 2020 at 17:57
fontspec
package). See the complete info provided by Sergei, far down this page.