3

What is the simplest method to tell XeTeX (not XeLaTeX) to use a font with Cyrillic letters and to apply Russian hyphenation rules?

Ideally i would like to not have to specify anything in the source files, but to get new commands rxetex and ramsxetex to compile sources in Russian.

jarnosc
  • 4,266
Alexey
  • 2,099

1 Answers1

3

Replace the preloaded cm text fonts with Unicode aware ones, and use them in your documents. Asumming that you have a working XeTeX installation, try the following:

  1. Install the OTF version of the cm-unicode set of fonts into your system. You can download them from CTAN.

  2. Run fc-cache on a terminal to update the font database cache.

  3. Copy the following code into cmunfonts.tex, and input this file at the beginning of your document.

\message{cm unicode fonts!}

\font\tenrm="[cmunrm]" at 10 pt% roman text
\font\sevenrm="[cmunrm]" at 7pt
\font\fiverm="[cmunrm]" at 5pt

\font\tenbf="[cmunbx]" at 10pt % boldface extended
\font\sevenbf="[cmunbx]" at 7pt
\font\fivebf="[cmunbx]" at 5pt

\font\tentt="[cmunbtl]" at 10pt % typewriter

\font\tensl="[cmunsl]" at 10pt % slanted roman

\font\tenit="[cmunti]" at 10pt % text italic

\endinput

Now try to xetex yourfile and see if that works.

In general, you will need to substitute the default 7bit cm text fonts with unicode text fonts in all your font definitions in your input files.

Now, to use russian hyphenation you need to use a format different than plain.fmt: that's untouchable. I recommend to you to install hyplain, the russian loader, and the hyphenation patterns (from hyph-utf8 package) from CTAN; check the documentation for hyplain (it's two pages), and at the appropriate place in the hylang.tex file, add russian as follows:

\input unicode-letters
\definelanguage{ru}{RU}{loadhyph-ru}
\refinelanguage{ru}{RU}{\hyphenmins{2}{2}\frenchspacing}{\nonfrenchspacing}
\addalias\russ{ru}{RU}

Make the format running xetex -ini *hyplain, and call xetex ^&hyplain yourfile and it will compile with cyrillic and russian hyphenation.

Then you can make a batch file or bash script rxetex to include the line xetex ^&hyplain %1 %2 %3 %4 %5 %6 to run your russian enabled xetex in a prompt.

I'm sorry, but I can see no way you may bypass the process of learning how to make a format.

Alexey
  • 2,099
jarnosc
  • 4,266
  • Nice to see that there are people using hyplain. ;-) – egreg Jun 09 '15 at 19:42
  • @egreg Do you think is it possible to dispense with the \preloaded fonts in the code above? —And yes, hyplain is a nice hack! – jarnosc Jun 09 '15 at 19:47
  • 1
    There's no need to define those \preloaded fonts: you can't store OpenType fonts in the format anyway, so you don't save time by defining those fonts: indeed, you lose some because you load fonts that probably you won't use. – egreg Jun 09 '15 at 19:54
  • Make sure you convert your input files to utf8 before trying to compile them. Files encoded in cp1251 will likely choke xetex. – jarnosc Jun 09 '15 at 22:15
  • xetex myfile does not work, i get ! Internal error: bad native font flag in 'map_char_to_glyph'. The error has to do with \bar command in math mode and with amsppt AMSTeX package -- if i remove one or the other, there is no error. – Alexey Jun 20 '15 at 21:40
  • It also compiles if i remove \input cmunfonts.tex. – Alexey Jun 21 '15 at 06:47
  • without more specific information, it may be hard to debug your file. Besides providing a snippet of code which triggers the error (the required Minimal Working Example), I just want to point out that amsppt.sty loads even more fonts, and that you also need to substitute the call for those extra cm text fonts with their cmu counterparts. – jarnosc Jun 22 '15 at 16:48
  • I think this may be the same problem: http://sourceforge.net/p/xetex/bugs/89/ – Alexey Jun 23 '15 at 20:11
  • Ok, if i want to patch amsppt.sty, could you tell me please, what to use instead of, for example, cmcsc10? I tried cmuncsc10, but it does not exist. Same problem with cmti7, etc. – Alexey Jun 23 '15 at 21:21
  • You stumbled upon a bug in the engine! Having read your references, the source, as I suspected, comes from several attempts at mixing OpenType and tfm fonts. Try to work around it using cmcyr and sticking to pdftex and either win1251 or encTeX, as suggested elsewhere. – jarnosc Jun 24 '15 at 01:19
  • I am afraid the other proposed solutions may not quite work without patching amsppt.sty anyway. At least the README of cyrplain package says to patch it. (Some instructions there are confusing, because i didn't find, for example, a definition of \fontprefix in cyrtex.cfg, and patching amsppt.sty uses this command). If i patch amsppt.sty to use unicode encoded fonts with all the glyphs i need, then maybe XeTeX will work for me. – Alexey Jun 24 '15 at 06:25
  • If you see the code above, you'll notice that some fonts are loaded \sevenrm="whatever" at 7pt. That order "fakes" a 7pt font otherwise nonexistent—not all unicode fonts are available at all sizes. Try to do the same with the fonts loaded with amsppt.sty. —Having said that, I have to warn you that the bug in XeTeX is triggered by the attempt to load otf and tfm fonts together, so you may stumble on the same stone after all. Moreover, you don't need to patch amsppt.sty; it is enough to load the font substitutions from a cmcyrppt.sty file, for instance. – jarnosc Jun 24 '15 at 18:31