# How to make LaTeX2e understand russian

## What's in this document

This document attempts to describe the steps necessary to typeset in Russian language using LaTeX document preparation system under Linux. Specifically, I talk about teTeX distribution of LaTeX. It is very likely that these instruction will work for other distributions of LaTeX and even for operating systems other than Linux.

## Conventions

The reader is assumed to have basic knowledge of the Linux operation system, that is, how to copy, move, delete, compress/decompress files. Throughout this document I give pathes relative to the LaTeX root directory. Most likely it is /usr/lib/texmf. I also refer you to CTAN sites. Primary CTAN (Comprehensive TeX Archive Network) sites are ftp.dante.de and ftp.tex.ac.uk. A list of CTAN mirrors can be found in teTeX installation in texmf/doc/help/CTAN.sites.

## What you will need

To follow the instructions contained in this document you will need the following pieces of software.
1. A reasonably recent version of LaTeX2e. I recommend teTeX 0.4 which includes LaTeX2e of 1996/12/01. Earlier version of LaTeX may work, but it should be LaTeX2e, not LaTeX 2.09. teTeX can be found on any CTAN site at /tex-archive/systems/unix/teTeX/. Most Linux distributions include teTeX, so if you have Linux you probably also have teTeX.
2. Babel package version 3.6. Most LaTeX distributions, teTeX in particular, come with Babel bundled with them. Note that you must have Babel 3.6, as earlier versions did not include support for russian language. If you have teTeX 0.4, you should be all set.
3. LH cyrillic fonts. Those can be found on any CTAN site at /tex-archive/fonts/LH, as well as on ftp.relcom.ru at /unix/text/fmt/tex/LHfonts.tar.gz.

## What to do

First of all, install LaTeX. Detailed description of how to do this is certainly beyond the scope of this document. If you have Red Hat Linux, you just need to install the following RPMs: tetex, tetex-latex, tetex-dvips, tetex-xdvi. Otherwise, follow the instructions found in various README files that came with your LaTeX distribution.

Actually, LaTeX already supports Russian language through its Babel package. The problem is that Babel's Russian works in LWN encoding, which means that you enter Russian text using latin transliteration. For example, you type "sobaka" to get the Russian word for "dog". However, most Russian-speaking Linux users have carefully read the Linux Cyrillic HOWTO (haven't you?) and know how to enter Russian letters directly from their keyboard. We will teach Babel to use LYC encoding, which corresponds to the "alternative" (CP 866) Russian encoding. We use this encoding, because so do LH fonts. "But I use KOI-8 encoding under Linux!", I hear you screaming. Yes, I know, so do I. We will address this issue, don't worry. Read on.

So, let's get down to work.

1. First we need the encoding definition file, LYCenc.def. Get it from here (it's gzipped and takes 1823 bytes). Alternatively, if you love to do everything yourself, you can create it yourself using texmf/tex/generic/babel/LWNenc.def as a template. To do it,
1. Copy LWNenc.def to LYCenc.def
2. Edit LYCenc.def and replace every occurence of character sequence LWN to LYC.
3. Go around line 90 in this file and replace the definitions of all \CYR* macros with real Russian letters in alternative encoding.
2. Now we need font description (.fd) files for LH fonts. Go to texmf/tex/generic/babel directory. You'll see a bunch of files whose names match LWN*.fd. To create the corresponding LYC*.fd files from them, use the following script:

#!/bin/csh
foreach lwnname (LWN*.fd)
set lycname = LYCexpr substr $lwnname 4 255 sed 's/LWN/LYC/g;s/wn/lh/g'$lwnname > \$lycname
end

(Note that if your csh is not in /bin, you'll need to change the first line. Tcsh will work, too). Run this script in texmf/tex/generic/babel directory (as root). Now you have LYC*.fd files in place.
3. Now we'll tell Babel to use LYC encoding instead of LWN. Go to your texmf/tex/generic/babel directory and edit russianb.ldf found there. Replace every occurence of the character sequence LWN with LYC (use replace function of your favourite editor). Then edit cyrmath.sty and do the same replace. Actually, this is it, but you may want to do some additional fiddling with russianb.ldf. For some obscure reason, Babel believes that in Russian language the symbols '!', '?', ':', ';' should be preceeded by a noticable space. Since it looks very strange, we will eliminate this weird behavior. Go around line 149 in russianb.ldf and comment out several lines, so that this fragment looks like this:
%\initiate@active@char{:}
%\initiate@active@char{;}
%\initiate@active@char{!}
%\initiate@active@char{?}
\initiate@active@char{"}
%  \bbl@activate{:}\bbl@activate{;}%
%  \bbl@activate{!}\bbl@activate{?}%
\bbl@activate{"}}
%\declare@shorthand{russian}{;}{%
%  \ifhmode
%    \ifdim\lastskip>\z@
%      \unskip\penalty\@M\thinspace
%    \else
%      \thinspace
%    \fi
%  \fi
%  \string;}
%\declare@shorthand{russian}{:}{%
%  \ifhmode
%    \ifdim\lastskip>\z@
%      \unskip\penalty\@M\thinspace
%    \else
%      \thinspace
%    \fi
%  \fi
%  \string:}
%\declare@shorthand{russian}{!}{%
%  \ifhmode
%    \ifdim\lastskip>\z@
%      \unskip\penalty\@M\thinspace
%    \else
%      \thinspace
%    \fi
%  \fi
%  \string!}
%\declare@shorthand{russian}{?}{%
%  \ifhmode
%    \ifdim\lastskip>\z@
%      \unskip\penalty\@M\thinspace
%    \else
%      \thinspace
%    \fi
%  \fi
%  \string?}
%\declare@shorthand{system}{:}{\string:}
%\declare@shorthand{system}{!}{\string!}
%\declare@shorthand{system}{?}{\string?}
%\declare@shorthand{system}{;}{\string;}

Now Babel is ready to use the LYC encoding
4. Now it's time to install the LH fonts. Copy all the source files (those with .mf extension) to a suitable directory, e.g. texmf/fonts/source/public/lh. Optionally, you can copy the .tfm (TeX Font Metrics) files to texmf/fonts/tfm/public/lh, but if you don't do it, the .tfm files will be generated automatically on demand.
5. Now, run texhash (as root) to update the texmf/ls-R database. Just type 'texhash' at your shell prompt and hit enter.
6. At this point LaTeX is ready to typeset in Russian, but it won't hyphenate Russian text. Now we'll teach it to hyphenate. To begin with, you'll need Russian hyphenation patterns. Here you may find yourself in one of the three situations:
• You already have Russian hyphenation patterns for LaTeX2e. Great! Use them.
• You have Russian hyphenation patterns from an old LaTeX 2.09 distribution (e.g. DOS-based emTeX). Then get this fragment, gunzip it and include in the beginning of your hyphenation pattern file.
• You don't have Russian hyphenation patterns at all. Then just download these.
So, one way or another, you have those hyphenation patterns in the file called ruhyphen.tex. Copy this file to texmf/tex/generic/hyphen. Then go to texmf/tex/generic/config and edit language.dat found there. Comment out any languages you don't need (but don't touch American, USenglish, or english - this must go first), and add the following line:
russian   ruhyphen.tex

Run texhash again.
7. Now we have to recreate the LaTeX format file latex.fmt to make LaTeX load russian hyphenation patterns. Go to texmf/tex/latex/config and issue the following command:
  initex 'latex.ini \dump'

This will produce a file named latex.fmt. Move this file to texmf/web2c directory.
8. Now, the final touch. All our Russian setup works in "alternative" encoding, while you are probably using KOI-8 on your Linux box. The quick (and dirty) solution would be to translate every LaTeX file to "alternative" before latexing. This would be very inconvenient and fortunately there is a better way. Use the koi2alt package, which you can find right here. Gunzip this file and put the resulting koi2alt.sty to a suitable directory, for example texmf/tex/latex/local (create this directory if necessary). Then run 'texhash' again. Warning: I have found this package on the Net, but made some corrections to it. The original package had a small glitch which resulted in the letter "yo" appearing as a capital "Ya" instead. So, if you took koi2alt.sty from somewhere else, make sure yours is correct.
9. One more step is necessary if you want LaTeX to properly distinguish between Russian uppercase and lowercase letter, particularily if you want LaTeX \uppercase and \lowercase commands to work. The latter is needed, for example, to properly format headings in amsart document class. So, to accomplish this, you need this koi8case package. Just like with koi2alt, gunzip this file and place to a suitable directory, such as texmf/tex/latex/local. Note that this package will work only for KOI8 encoding. Warning: I created this package myself, but I'm not a LaTeX guru, so I can't be sure that I followed the safest and most elegant way to go. Use this package at your own risk.
Ufff... That's it! Now test your Russian setup. The following fragment demonstrates a template for creating Russian documents:
\documentclass{article}
\usepackage[russian]{babel}
\usepackage{koi2alt}
\usepackage{koi8case}
\begin{document}

... type something in Russian here ...

\end{document}

Run such file though LaTeX and then use xdvi to preview it. Be prepared to wait for METAFONT to generate necessary .tfm (for LaTeX) and .pk (for xdvi) files. Don't worry, this happens only when you use Russian fonts for the first time. Now you should see your Russian text beautifully typeset in LaTeX!

If you want koi2alt and koi8case packages to always be used whenever you typeset document in russian, you can add the following two lines towards the end of russianb.ldf in texmf/tex/generic/babel (right before the line \ldf@finish{russian}):

\AtEndOfPackage{\RequirePackage{koi2alt}}
\AtEndOfPackage{\RequirePackage{koi8case}}

Now you don't need to include \usepackage{koi2alt} \usepackage{koi8case} in each document, it is done automatically.

## Disclaimer

What I described here worked for me. Although it is very unlikely that it won't work for you, I make no warranties. Use these instructions at your own risk. If you have troubles, I may be able to help you. Feel free to contact me at lz@ecos.kharkov.ua.

## Credits

Most of the information here was taken from an article posted to FIDOnet newsgroup RU.LINUX on 10 Oct 1996 by Alex Kicelew (Alex_Kicelew@p7.f194.n5020.z2.fidonet.org). I'd like to thank this person for his very informative message. Also, I've found some help in LH support package by Sergei O. Naoumov (serge@astro.unc.edu).