Difference between revisions of "Russian"

From Wiki
Jump to navigation Jump to search
(→‎Using cyrillic with ConTeXt MkIV: gyre lacks cyrillic glyphs; added simple example with simplefonts (that WORKS))
m (typo)
Line 7: Line 7:
 
Probably, the most simple way to get ''some'' cyrillic text in your context is to use Computern Modern Cyrillic fonts (in Debian you need texlive-lang-cyrillic and texlive-fonts-extra packages) and ''simplefont'' module:
 
Probably, the most simple way to get ''some'' cyrillic text in your context is to use Computern Modern Cyrillic fonts (in Debian you need texlive-lang-cyrillic and texlive-fonts-extra packages) and ''simplefont'' module:
  
<textcode>
+
<texcode>
 
\usemodule[simplefonts]
 
\usemodule[simplefonts]
 
\setmainfont[cmromancyrillic]
 
\setmainfont[cmromancyrillic]
Line 13: Line 13:
 
Пр{\it ив}ет, \bf мир!
 
Пр{\it ив}ет, \bf мир!
 
\stoptext
 
\stoptext
</textcode>
+
</texcode>
  
 
This example restricts you to using luatex engine, though, and also compiles a few times longer than any other example here.
 
This example restricts you to using luatex engine, though, and also compiles a few times longer than any other example here.

Revision as of 15:58, 2 March 2011

< Fonts | Encodings and Regimes >

Using cyrillic with ConTeXt MkIV

Note: Since january 2009 CONTeXT lacks cyrillic Gyre glyphs.

Probably, the most simple way to get some cyrillic text in your context is to use Computern Modern Cyrillic fonts (in Debian you need texlive-lang-cyrillic and texlive-fonts-extra packages) and simplefont module:

\usemodule[simplefonts]
\setmainfont[cmromancyrillic]
\starttext
Пр{\it ив}ет, \bf мир!
\stoptext

This example restricts you to using luatex engine, though, and also compiles a few times longer than any other example here.

Note: The examples in this section were tested on recent (2008-10) ConTeXt minimals. If something does not work as written feel free to change them.

After installing the latest and greatest ConTeXt distribution and especially while trying to use MkiV you may notice that your old typescript definitions does not work anymore. For guidance about adjusting typescripts see upcoming ConTeXt manual (especially chapters about fonts and typography). Here are examples for writing cyrillic using only fonts that comes with ConTeXt. For quick start try:

\usetypescript[postscript]
\setupbodyfont[postscript,10pt]
\starttext
Немного русского текста для пробы.
\stoptext

Please note that in ConTeXt MkIV UTF-8 input encoding is the default, so writing \enableregime[utf] is no longer necessary.

Nowadays the ConTeXt minimals distribution includes TeX Gyre fonts. Most of them contain cyrillic characters and all low-level mappings are already predefined (see type-otf.tex), so to use TeX Gyre fonts a few simple typeface definitions would suffice.

\starttypescript[gyre]
\definetypeface [gyre-pala] [rm] [serif] [pagella]
\definetypeface [gyre-pala] [ss] [sans]  [heros]
\definetypeface [gyre-pala] [tt] [mono]  [courier]
\definetypeface [gyre-pala] [mm] [math]  [palatino]

\definetypeface [gyre-book] [rm] [serif] [bonum]
\definetypeface [gyre-book] [ss] [sans]  [adventor]
\definetypeface [gyre-book] [tt] [mono]  [courier]
\definetypeface [gyre-book] [mm] [math]  [palatino]
\stoptypescript

\definetypeface [gyre-schol] [rm] [serif] [schola]
\definetypeface [gyre-schol] [ss] [sans]  [adventor]
\definetypeface [gyre-schol] [tt] [mono]  [courier]
\definetypeface [gyre-schol] [mm] [math]  [palatino]
\stoptypescript

\definetypeface [gyre-termes] [rm] [serif] [termes]
\definetypeface [gyre-termes] [ss] [sans]  [adventor]
\definetypeface [gyre-termes] [tt] [mono]  [courier]
\definetypeface [gyre-termes] [mm] [math]  [palatino]

\definetypeface [gyre-pala] [rm] [serif] [pagella]
\definetypeface [gyre-pala] [ss] [sans]  [heros]
\definetypeface [gyre-pala] [tt] [mono]  [courier]
\definetypeface [gyre-pala] [mm] [math]  [palatino]
\stoptypescript

If someone tell me why small-caps doesn't work with these definitions, this would be perfect!

Put these in type-loc.tex file, place it somewhere luatex can find it (texml-local tree is a good candidate), regenerate filename cache (luatools --generate), and use as:

\usetypescript[gyre]
\setupbodyfont[gyre-pala] % can be gyre-termes, gyre-book, etc.
\startext
Ещё немного кириллицы.
\stoptext

Note that I don't use cursor font here as it seem to not have cyrillic characters. If you don't like these combinations modify the definitions as you see fit.

For complete russian language typesetting a few adjustments to config files are needed:

  • Uncomment \installlanguage [\s!ru] [\c!state=\v!start] in cont-usr.tex (can be found in tex/texmf-context/tex/context/config in minimals.
  • Add \input lang-cyr somewhere in cont-usr.tex (for russian month names, translated labels like "table of contents", etc.; found in tex/texmf-context/tex/context/user in minimals).
  • Don't forget to change your language in documents (\mainlanguage[ru] for mainly russian documents).

Russian (Cyrillic) fonts and UTF

It is now possible (from ConTeXt version 2005.01.26 or 2005-01-31) to type Russian (cyrillic) letters directly in your .tex file using UTF-8 encoding. I have only tested this on TeXLive 2004, but I guess it would work on any distribution as long as you have the cm-super fonts installed (On TeXLive you had to generate the tfm files needed using the afm2tfm application (see furhter down on this page for a small python script that enables you to create all tfm files), or by using the fonts in LaTeX). Here is a minimal(?) working file.

\enableregime[utf]
\useencoding[cyr]

\definetypeface [russian]
  [rm] [serif] [computer-modern] [default] [encoding=t2a]

\setupbodyfont[russian]
\starttext
Мама и Папа % Some Russian characters
\stoptext

Russian (Cyrillic) fonts and Windows 1251

The following example should work if you save your file in the Windows 1251 encoding:

\definetypeface [russian]
  [rm] [serif] [computer-modern] [default] [encoding=t2a]

\definetypeface [swedish]
  [rm] [serif] [latin-modern] [default] [encoding=texnansi]
\setupbodyfont[russian]

\starttext
Some russian text:
Там можно встретить медведей.

Some swedish text:
{\switchtobodyfont[swedish]D\"ar kan man m\"ota bj\"ornar.}

\stoptext

At least it works here with TeXLive 2004.

Russian (Cyrillic) fonts and koi8-r (koi8r)

For koi8-r input encoding try this:

\useregime[cyr] % loads input regimes
\enableregime[koi8-r]

\starttext
Тест кои8-р текста.
\stoptext

For this example to work you need some cyrillic fonts, which is not included in default ConTeXt distribution. AFAIK cm-super is one of the most comprehensive cyrillic font packages. It can replace most fonts in cont-lmt. There is also small type1 font package pscyr.

If you have one of these, you need to add this before \starttext:

For cm-super try:

\usetypescript[modern-base][t2a] % switch default typescipt
\setupbodyfont[modern]

or for pscyr:

\usetypescript[pscyr][t2a]
\setupbodyfont[pscyr]

But you need to make sure that all typescript definitions are in place.

Example typescript for PSCyr can be downloaded from http://radhelorn.freeownhost.com/files/type-pscyr.tex. Place it in the same dir as your tex file or in ConTeXt user directory and add this command before setting typescripts:

\usetypescriptfile[type-pscyr]

If all files is on their places this should work "out of the box".

The python script

Ok, I am not a programmer, so this could probably be done in a cleaner way. However, it works for me. (A bit enhanced/modernized now...)

#!/usr/bin/python
import os

# Set these paths to what they should be in your case
mapfile="/texmf/fonts/map/dvips/cm-super/cm-super-t2a.map"
encfile="cm-super-t2a.enc"
tfmoutdir="/texmf/fonts/tfm/public/cm-super/"

f=file(mapfile, 'rU')

# First read a line that is a comment.
a=f.readline()
print a

# Loop over the rest of the lines
for currentline in f:
  splitspace= currentline.split(" ")
  tfmname=splitspace[0]
  afmname=splitspace[1].lower()
  commandtorun= "afm2tfm %s.afm -T %s %s%s.tfm" % (afmname, encfile, tfmoutdir, tfmname)
  print "Running: " + commandtorun
  os.popen(commandtorun)

f.close()

External Links

  • Russian Transliteration - Russian translit free online transliteration service for Microsoft Office and Internet Explorer