1

The string.lower function Lua does not work with Cyrillic. How to fix it?

enter image description here

MWE:

% !TeX program = lualatex
\documentclass[12pt]{article}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=modern]{russian}
\setotherlanguage{english}
\defaultfontfeatures{Ligatures={TeX},Renderer=Basic}
\setmainfont{Times New Roman}

\def\ptestcyr{%
\directlua{
tex.print(string.lower("Supervisory Control And Data Acquisition"),"\string\\newline")
tex.print(string.lower("Ямало-Ненецкий Автономный Округ"))
}%
}
\begin{document}
\noindent\ptestcyr
\end{document}
5
  • that is a lua question, see e.g. stackoverflow.com/a/47860127/11796366. In LaTeX I would use \MakeLowercase{Ямало-Ненецкий Автономный Округ}. Unrelated but don't use Renderer=Basic, that is really basic and used in math. Commented Nov 29, 2022 at 10:14
  • This seems to be unrelated to LaTeX. If you run print(string.lower("Привет Мир")) with Lua, it doesn't work. I think you write your own Lua function to do this. Commented Nov 29, 2022 at 10:17
  • In order for string.lower to work with Cyrillic, you need to set the Russian locale by calling os.setlocale. If you have a Russian-language OS, it is enough to call os.setlocale("") with an empty locale name - the default locale of the OS will be substituted. But it doesn't work in LuaLaTeX. Thanks @Ulrike Fischer.
    – Youra_P
    Commented Nov 29, 2022 at 10:54
  • 1
    Thanks, @Michael Fraiman.
    – Youra_P
    Commented Nov 29, 2022 at 10:54
  • I'm not sure Yamalia residents would like to see the name of their Okrug lowercased though?
    – Marijn
    Commented Nov 29, 2022 at 14:44

1 Answer 1

1

As mentioned in the comments, you can write your own Tim Toady function.

Based on utf8data that you can download from https://github.com/artemshein/luv/blob/master/utf8data.lua and some code found in https://github.com/Stepets/utf8.lua/issues/13:

\documentclass[12pt]{article}
\usepackage{polyglossia}
\usepackage{luacode}
\setdefaultlanguage[spelling=modern]{russian}
\setotherlanguage{english}
\setmainfont{DejaVu Serif}
\begin{luacode}
require("utf8data")
function timtowtdilower(str_in)
  local lc_str = str_in:gsub(utf8.charpattern,utf8_uc_lc)
  return lc_str
end
\end{luacode}
\def\ptestcyr{%
\directlua{
tex.print(string.lower("Supervisory Control And Data Acquisition"),"\string\\newline")
tex.print(timtowtdilower("Ямало-Ненецкий Автономный Округ"))
}%
}
\begin{document}
\noindent\ptestcyr
\end{document}

enter image description here

Note that the font is different because I don't have Times New Roman installed.

1
  • Thanks, @Marijn.
    – Youra_P
    Commented Nov 29, 2022 at 15:39

You must log in to answer this question.

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