From 1bb826132f327a8ae93f9cc73b6cd803f436becb Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 29 Nov 2011 10:18:10 +0100 Subject: initial: module skeleton, mp code, conversion code --- .../third/cyrillicnumbers/cyrillicnumbers.lua | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tex/context/third/cyrillicnumbers/cyrillicnumbers.lua (limited to 'tex/context/third/cyrillicnumbers/cyrillicnumbers.lua') diff --git a/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua b/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua new file mode 100644 index 0000000..d47c744 --- /dev/null +++ b/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua @@ -0,0 +1,99 @@ +#!/usr/bin/env texlua +-------------------------------------------------------------------------------- +-- FILE: cyrillicnumbers.lua +-- USAGE: called by t-cyrillicnumbers.mkiv +-- DESCRIPTION: part of the Cyrillic Numbers module for ConTeXt +-- REQUIREMENTS: recent ConTeXt MkIV and LuaTeX +-- AUTHOR: Philipp Gesang (phg), +-- VERSION: hg tip +-- CREATED: 2011-11-29 10:06:00+0100 +-------------------------------------------------------------------------------- +-- + +--- read this first: +--- +--- Жолобов, О. Ф.: *Числительные*. In: *Историческая грамматика древнерусского +--- языка*, vol. 4, Moskva 2006, pp. 58--63 +--- +--- Trunte, Nikolaos H.: *Altkirchenslavisch*. In: *Словѣньскъи ѩꙁъікъ. +--- Ein praktisches Lehrbuch des Kirchenslavischen in 30 +--- Lektionen. Zugleich eine Einführung in die slavische +--- Philologie*, vol. 1, München ⁵2005, pp. 161ff. + +--- or have a glance at these: +--- http://www.pravpiter.ru/zads/n018/ta013.htm +--- http://www.uni-giessen.de/partosch/eurotex99/berdnikov2.pdf +--- + +local mathfloor = math.floor +local tableconcat = table.concat +local utf8char = unicode.utf8.char +local utfupper = unicode.utf8.upper + +thirddata = thirddata or { } + +local cyrillic_placetitlo = true + +local cyrillic_numerals = { + { "а", "в", "г", "д", "е", "ѕ", "з", "и", "ѳ", }, + { "і", "к", "л", "м", "н", "ѯ", "о", "п", "ч", }, + { "р", "с", "т", "у", "ф", "х", "ѱ", "ѡ", "ц", }, +} +local cyrillic_1k = "҂" +local cyrillic_100k = utf8char(0x488) -- combining hundred thousands sign +local cyrillic_1m = utf8char(0x489) -- combining million sign +local cyrillic_titlo = utf8char(0x483) -- combining titlo + +local concat_cyrillic_nums = function (chars, upper) + local result = "" + for i=#chars, 1, -1 do + local this = chars[i] + if this then + if upper then this = utfupper(this) end + if i > 3 then + result = result .. cyrillic_1k .. this + else + result = result .. this + end + end + end + if cyrillic_placetitlo then -- not all fonts do this well + result = result .. cyrillic_titlo + end + return result +end + +local do_tocyrillic do_tocyrillic = function (n, result) + if n < 1000 then + local mod100 = n % 100 + if #result == 0 and mod100 > 10 and mod100 < 20 then + result[#result+1] = "і" + result[#result+1] = cyrillic_numerals[1][mod100%10] or false + else + result[#result+1] = cyrillic_numerals[1][mathfloor(n%10)] or false + result[#result+1] = cyrillic_numerals[2][mathfloor((n%100)/10)] or false + end + result[#result+1] = cyrillic_numerals[3][mathfloor((n%1000)/100)] or false + else + result = do_tocyrillic(n%1000, result) + result = do_tocyrillic(mathfloor(n/1000), result) + end + return result +end + +local tocyrillic = function (n) + local chars = do_tocyrillic(n, { }) + return concat_cyrillic_nums(chars) +end + +local Tocyrillic = function (n) + local chars = do_tocyrillic(n, { }) + return concat_cyrillic_nums(chars, true) +end + +converters.tocyrillic = tocyrillic +converters.cyrillicnumerals = tocyrillic +converters.Cyrillicnumerals = Tocyrillic + +function commands.cyrillicnumerals (n) context(tocyrillic(n)) end +function commands.Cyrillicnumerals (n) context(Tocyrillic(n)) end -- cgit v1.2.3