diff options
Diffstat (limited to 'tex/context/third')
-rw-r--r-- | tex/context/third/cyrillicnumbers/cyrillicnumbers.lua | 50 | ||||
-rw-r--r-- | tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv | 142 |
2 files changed, 161 insertions, 31 deletions
diff --git a/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua b/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua index 1c252ae..72ed5e4 100644 --- a/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua +++ b/tex/context/third/cyrillicnumbers/cyrillicnumbers.lua @@ -37,6 +37,7 @@ local utfupper = unicode.utf8.upper local cyrnum = { placetitlo = "font", + prefer100k = false, titlolocation = "final", -- above final digit titlospan = 3, -- only with mp drawdots = true, @@ -90,12 +91,41 @@ cyrnum.yes_synonyms = { ["true"] = true, } +cyrnum.no_synonyms = { + no = true, + nope = true, + ["false"] = true, +} + +local handle_plus1k = function (digit) + local before, after + if digit == 7 then + after = cyrillic_1m + elseif cyrnum.prefer100k and digit == 6 then + after = cyrillic_100k + elseif digit > 3 then -- insert thousand sign + before = cyrillic_1k + end + return before, after +end + +-- digit list = { +-- [1] = character to be printed +-- [2] = real digit of character +-- [3] = print this before character (e.g. thousand signs) +-- [4] = print this after character (e.g. million signs) +-- } + local digits_only = function (list) local result = { } for i=1, tablemaxn(list) do local elm = list[i] if type(elm) == "string" then - result[#result+1] = elm + local before, after + if i > 3 then + before, after = handle_plus1k(i) + end + result[#result+1] = { elm, i, before, after } -- i contains the real digit end end return result @@ -120,12 +150,24 @@ local titlofuncs = { mp = function (list) local result = { } local titlospan = cyrnum.titlospan - local titlostart = titlospan and #list > titlospan and #list-titlospan or 1 + local titlotype = cyrnum.titlotype + local titlostart = #list -- default to “all” + if titlotype == true then -- number + titlostart = (#list >= titlospan) and titlospan or #list + end for i=tablemaxn(list), 1, -1 do + --local char, digit, before, after = list[i][1], list[i][2], list[i][ + local char, digit, before, after = unpack(list[i]) if i == titlostart then result[#result+1] = start_titlo end - result[#result+1] = list[i] + if before then + result[#result+1] = before + end + result[#result+1] = char + if after then + result[#result+1] = after + end end result[#result+1] = stop_titlo return result @@ -138,7 +180,7 @@ local concat_cyrillic_nums = function (list, upper) local digits = digits_only(list) -- strip placeholders local nlist, ndigits = tablemaxn(list), tablemaxn(digits) dbg(list) - dbg(digits) + --dbg(digits) local titlo = titlofuncs[cyrnum.placetitlo] if titlo then result = tableconcat(titlo(digits)) diff --git a/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv b/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv index 79a47e6..600bee4 100644 --- a/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv +++ b/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv @@ -16,14 +16,29 @@ \unprotect +\startinterface all + \setinterfacevariable {cyrillicnumerals} {cyrillicnumerals} + \setinterfacevariable {Cyrillicnumerals} {Cyrillicnumerals} + \setinterfacevariable {cyrnum} {cyrnum} + \setinterfacevariable {dots} {dots} + \setinterfacevariable {dotsymbol} {dotsymbol} + \setinterfacevariable {penwidth} {penwidth} + \setinterfacevariable {preferhundredk} {preferhundredk} + \setinterfacevariable {titlolocation} {titlolocation} + \setinterfacevariable {titlomode} {titlomode} + \setinterfacevariable {titlospan} {titlospan} + \setinterfacevariable {titlo} {titlo} +\stopinterface + \definenamespace [cyrnum] [ - name=cyrnum, - type=module, - setup=list, - parent=cyrnum, - style=no, - version=hg-tip, - comment=cyrillic numbers, + command=\v!yes, + comment=cyrillic numbers, + \s!name=\v!cyrnum, + \s!parent=\v!cyrnum, + setup=\v!list, + style=\v!no, + type=module, + version=hg-tip, ] \registerctxluafile{cyrillicnumbers} @@ -31,25 +46,25 @@ \def\cyrnumsetvariables{% \startluacode local tc = thirddata.cyrnum - tc.placetitlo = "\cyrnumparameter{titlo}" - tc.titlospan = tonumber("\cyrnumparameter{titlospan}") or false - tc.titlolocation = tc.last_synonyms["\cyrnumparameter{titlolocation}"] and "l" or "m" - tc.drawdots = tc. yes_synonyms["\cyrnumparameter{dots}"] or false - tc.dotsymbol = "\cyrnumparameter{dotsymbol}" + tc.placetitlo = "\cyrnumparameter{\v!titlo}" + tc.titlolocation = tc.last_synonyms["\cyrnumparameter{\v!titlolocation}"] and "l" or "m" + tc.prefer100k = tc. yes_synonyms["\cyrnumparameter{\v!preferhundredk}"] or false + tc.drawdots = tc. yes_synonyms["\cyrnumparameter{\v!dots}"] or false + tc.dotsymbol = "\cyrnumparameter{\v!dotsymbol}" + + local span = "\cyrnumparameter{\v!titlospan}" + local num = tonumber(span) + if num then + tc.titlotype = true + tc.titlospan = num + elseif span == "all" then + tc.titlotype = false + end \stopluacode% } -\appendtoks \cyrnumsetvariables \to \everysetupcyrnum - -\setupcyrnum[ - titlo=mp, % font|mp|no - titlospan=3, % n|all - titlolocation=middle, % final|middle -- only effective if using the font’s titlo - dots=\v!yes, % yes|no - dotsymbol=·, - penwidth=3, - titlomode=5, -] +\appendtoks \setuevalue{\currentcyrnum}{\do_cyrnum[\currentcyrnum]} \to \everydefinecyrnum +\appendtoks \cyrnumsetvariables \to \everysetupcyrnum \startmoduletestsection \ctxlua{thirddata.cyrnum.debug = true} @@ -269,17 +284,90 @@ \let\cyrnumdrawtitlo\cyrnum_titloframe %% for protected context %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%% Interfacing with the Lua functions. +%D \subject{Interfacing with the Lua functions} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\def\cyrillicnumerals#1{\ctxcommand{cyrillicnumerals(\number#1)}} -\def\Cyrillicnumerals#1{\ctxcommand{Cyrillicnumerals(\number#1)}} +%D \macros +%D {definecyrnum} +%D +%D User interface to the main conversion routines. The definition +%D macro autogenerates the primary user-level macro, which in turn +%D relies \type{\setupcyrnum} for argument processing (see above on +%D \at{Page}[setupdef]). +%D +%D Example usage: +%D +%D \starttyping +%D \definecyrnum[titlofree] +%D \setupcyrnum [titlofree][titlo=no] +%D \starttext +%D \titlofree{42} +%D \stoptext +%D \stoptyping + +\unexpanded\def\do_cyrnum[#1]{% + \edef\currentcyrnum{#1}% + \dosingleempty\dodo_cyrnum% +} + +\def\dodo_cyrnum[#1]{% + \iffirstargument + \doifassignmentelse{#1}{\setupcyrnum[\currentcyrnum][#1]}\relax + \else + \setupcyrnum + \fi + \dododo_cyrnum% +} + +\def\dododo_cyrnum#1{% + \ctxcommand{cyrillicnumerals(\number#1)}% +} + +%D \macros +%D {setupcyrnum} +%D +%D The \type{\setupcyrnum} and \type{\definecyrnum} macros are +%D autogenerated via the namespace. + +\setupcyrnum[ + \v!dots=\v!yes, % yes|no + \v!dotsymbol=·, + \v!penwidth=.66pt, + \v!preferhundredk=no, + \v!titlolocation=\v!middle, % final|middle -- only effective if using the font’s titlo + \v!titlomode=5, + \v!titlospan=3, % n|all + \v!titlo=\v!mp, % font|mp|no +] + +%D \macros +%D {cyrillicnumerals,Cyrillicnumerals} +%D +%D Conforming to the standard \CONTEXT\ naming scheme as employed +%D with number conversion macros, we define two macros for use with +%D conversions. As there is no definition for uppercase conversion, +%D the macro \type{\Cyrillicnumerals} exists only for compatibility +%D reasons. +%D +%D Also, we setup two corresponding conversions \type{cyr} and +%D \type{Cyr} for use with e.g. enumerations, headings, counters +%D {\italic\letterampersand}c. + +\definecyrnum[\v!cyrillicnumerals] +\definecyrnum[\v!Cyrillicnumerals] \defineconversion[cyrillicnumerals][\cyrillicnumerals] \defineconversion[Cyrillicnumerals][\Cyrillicnumerals] \defineconversion[cyr] [\cyrillicnumerals] \defineconversion[Cyr] [\Cyrillicnumerals] +%D \macros +%D {cyrnum} +%D +%D The default user macro is defined as \type{\cyrnum}. + +\definecyrnum[\v!cyrnum] + \unprotect \endinput -% vi:ft=context:fo=co:ts=4:expandtab:sw=4 +% vi:ft=context:fo=co:ts=2:expandtab:sw=2 |