On 11/21/2012 10:08 AM, Acidrums4 wrote:
Hello there and thanks for finally let me into this mailing list!

So I tried to hack the macro given in the ConTeXt wiki
(http://wiki.contextgarden.net/Page_numbering_in_words) to write pagenumbering
in words in spanish, my native language. Things were great until I had to
reach the 100th page. ConTeXt claims when compiling, but I don't know how to
fix the macro so it can write hundred-numbers.

'Cien' is 100 for spanish. 'Ciento uno' for 101, 'ciento dos' for 102 and so
(You can see a more detailed example in
http://spanish.about.com/cs/forbeginners/a/cardinalnum_beg.htm). So basically
I need to prepend the word 'cien' for each word number from 1 to 99 to write
the one-hundreds, 'doscientos' for the two-hundreds... Here is my dirty hacked
version of the macro (you may save it as 'numstr.tex' for compiling), and a
minimal example as follows:

\input numstr
\defineconversion[numstring][\numstr]
\setupuserpagenumber[numberconversion=numstring]
\starttext
\dorecurse{100}{\recurselevel\page}
\stoptext

I'm such a noob with TeX and I cannot figure out how to do this, and I need
this for this friday!. However, Aditya in the TeX section of StackExchange
(http://tex.stackexchange.com/questions/82722/context-page-numbering-in-words-
for-spanish#comment178155_82722) told me that I could do this witk Lua
(editing the file core-con.lua, as seen in
http://repo.or.cz/w/context.git/blob/HEAD:/tex/context/base/core-con.lua
), 'cause I'm using MkIV for doing this. But I don't know anything about Lua
(seems pretty easy, but I don't know how to test the code Aditya gave me) and
If I knew how to do that, I don't know how to make it work in my document...
All I could do is translate the 'words' array to spanish, but I couldn't do
more... Could you guys give me a hand on this? Thank you so much!

We can add a converter to core-con, but you have to do the checking (and tuning):

local floor = math.floor
local concat = table.concat

local verbose = { }

local words = {
        [1] = "uno",
        [2] = "dos",
        [3] = "tres",
        [4] = "cuatro",
        [5] = "cinco",
        [6] = "seis",
        [7] = "siete",
        [8] = "ocho",
        [9] = "nueve",
       [10] = "diez",
       [11] = "once",
       [12] = "doce",
       [13] = "trece",
       [14] = "catorce",
       [15] = "quince",
       [16] = "dieciséis",
       [17] = "diecisiete",
       [18] = "dieciocho",
       [19] = "diecinueve",
       [20] = "veinte",
       [21] = "veintiuno",
       [22] = "veintidós",
       [23] = "veintitrés",
       [24] = "veinticuatro",
       [25] = "veinticinco",
       [26] = "veintiséis",
       [27] = "veintisiete",
       [28] = "veintiocho",
       [29] = "veintinueve",
       [30] = "treinta",
       [40] = "cuarenta",
       [50] = "cincuenta",
       [60] = "sesenta",
       [70] = "setenta",
       [80] = "ochenta",
       [90] = "noventa",
      [100] = "ciento",
      [200] = "doscientos",
      [300] = "trescientos",
      [400] = "cuatrocientos",
      [500] = "quinientos",
      [600] = "seiscientos",
      [700] = "setecientos",
      [800] = "ochocientos",
      [900] = "novecientos",
     [1000] = "mil",
   [1000^2] = "millón",
   [1000^3] = "millones",
}

function verbose.spanish(n)
    local w = words[n]
    if w then
        return w
    end
    local t = { }
    local function compose_one(n)
        local w = words[n]
        if w then
            t[#t+1] = w
            return
        end
        local a, b = floor(n/100), n % 100
        if a == 10 then
            t[#t+1] = words[1]
            t[#t+1] = words[1000]
        elseif a > 0 then
--             t[#t+1] = words[a]
            t[#t+1] = words[100]
        end
        if words[b] then
            t[#t+1] = words[b]
        else
            a, b = floor(b/10), n % 10
            t[#t+1] = words[a*10]
t[#t+1] = "y"
            t[#t+1] = words[b]
        end
    end
    local function compose_two(n,m)
        if n > (m-1) then
            local a, b = floor(n/m), n % m
            if a > 0 then
                compose_one(a)
            end
            t[#t+1] = words[m]
            n = b
        end
        return n
    end
    n = compose_two(n,1000^4)
    n = compose_two(n,1000^3)
    n = compose_two(n,1000^2)
    n = compose_two(n,1000^1)
    if n > 0 then
        compose_one(n)
    end
    return #t > 0 and concat(t," ") or tostring(n)
end

verbose.es = verbose.spanish

print(verbose.spanish(31))
print(verbose.spanish(101))
print(verbose.spanish(199))

sort of the english one with some patches (exceptions can be added to the table if needed)



-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
    tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to