5

Transliteration from cyrillic to latin characters can be done in LuaLaTeX with the help of directlua as shown by @DavidCarlisle: Create a mapping for transliteration from cyrillic to latin in LuaLaTeX

This method is a LuaLaTeX alterative to a good XeLaTeX method which exploits Mapping, as shown by @egreg in his Answer to Using XeTeX for automatic transliteration of cyrillic letters

It has actually at least one bug to be fixed, since, with the same 'TeX Gyre Adventor' font I have to work with, XeLaTeX Mapping perfectly transliterates acute accented cyrillic vowel 'и́' to 'í', while directlua separates the acute accent from the letter.

\documentclass{article}
\usepackage{fontspec}
\usepackage{ifluatex,ifxetex}

%Lua does not load cyrillics of 'TeX Gyre Adventor' if loaded as usual \setmainfont{TeX Gyre Adventor}. So I had to bypass this problem with the declarations below:
\newfontfamily{\LuaMainFont}{texgyreadventor-regular.otf}
\newfontfamily{\XeMainFont}{TeX Gyre Adventor}

\newfontfamily{\TranslitFont}[Mapping=cyrillic-to-latin]{TeX Gyre Adventor}%{Linux Libertine O}%

\setlength{\parindent}{0pt}

\def\Accents{И и И́ и́}

\begin{document}

\ifluatex
    \LuaMainFont
    This is LuaLaTeX \par \vspace{\baselineskip}

    Здравствуй, Мир \par
    \Accents\ \vspace{\baselineskip}

    Translitteration by \verb\directlua\ \vspace{\baselineskip} 
    \directlua{require("cyrtr2")}

    Здравствуй, Мир \par
    И и    И́ и́ \\   %problems with the 'i' dot

\else
    \XeMainFont
    This is XeLaTeX \par \vspace{\baselineskip}

    Здравствуй, Мир \par
    \Accents \par \vspace{\baselineskip}

    Translitteration by \verb\Mapping=cyrillic-to-latin\ \vspace{\baselineskip} 
    \TranslitFont

    Здравствуй, Мир \par
    \Accents   %no problems with the 'i' dot
\fi

\end{document}

Unefficient transliteration with \directlua

Efficient transliteration with XeLaTeX Mapping

NOTE 1: this problem crosses the Question Misplaced Accents in Cyrillic Text, since as it can be seen in the example, acute accent of untransliterated И́ appears misplaced.

NOTE 2: LuaLaTeX loads TeX Gyre Adventor with the entire set of cyrillic fonts if loaded with the file name 'texgyreadventor-regular.otf'. By the contrary, XeLaTeX does not loads TeX Gyre Adventor's cyrillics if not loaded with the simple label 'TeX Gyre Adventor'. This is commented in the code reported above.

1 Answer 1

4

enter image description here

You can replace the pair И followed by an accent with the precomposed Í so long as you make sure that you search/replace for the longer string before the shorter one.

I just added two more gsub replacements to the file:

function cyrtr (s)
return
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
string.gsub(
s,
'А','A'),
'Б','B'),
'В','V'),
'Г','G'),
'Д','D'),
'Е','E'),
'Ж','Ž'),
'З','Z'),
'И́','Í'),
'И','I'),
'К','K'),
'Л','L'),
'М','M'),
'Н','N'),
'О','O'),
'П','P'),
'Р','R'),
'С','S'),
'Т','T'),
'У','U'),
'Ф','F'),
'Ц','C'),
'Ч','Č'),
'Ш','Š'),
'Э','Ė'),
'Ю','Ju'),
'Я','Ja'),
'Ё','Ë'),
'а','a'),
'б','b'),
'в','v'),
'г','g'),
'д','d'),
'е','e'),
'ж','ž'),
'з','z'),
'и́','í'),
'и','i'),
'й','j'),
'к','k'),
'л','l'),
'м','m'),
'н','n'),
'о','o'),
'п','p'),
'р','r'),
'с','s'),
'т','t'),
'у','u'),
'ф','f'),
'ц','c'),
'ч','č'),
'ш','š'),
'э','ė'),
'ю','ju'),
'я','ja'),
'ё','ë'),
'і','i'),
'І','I'),
'є','je'),
'Ѩ','Je'),
'Х','X'),
'х','x'),
'И','I'),
'Щ','Šč'),
'Ы','Y'),
'щ','šč'),
'ы','y')
end


luatexbase.add_to_callback(
"process_input_buffer",
cyrtr,
"cyrillic transliteration")
3
  • It definitivelly helped to fix the problem. Thank you! Commented Jan 5, 2016 at 17:23
  • The formatting is very peculiar on my screen, like two columns have been dissociated, and the second has been moved below the first, instead of side by side. ??? Commented May 10, 2023 at 0:20
  • @barbarabeeton that's how I wrote it, shows the structure and allows easy addition of more lines which was point of this answer Commented May 10, 2023 at 0:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .