ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: ConTeXt: Page numbering in words for spanish
Date: Wed, 21 Nov 2012 11:26:49 +0100	[thread overview]
Message-ID: <50ACAC69.9060603@wxs.nl> (raw)
In-Reply-To: <1410329.t7YnaHOuHa@localhost>

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	other threads:[~2012-11-21 10:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-21  9:08 Acidrums4
2012-11-21 10:26 ` Hans Hagen [this message]
2012-11-21 11:25   ` Sietse Brouwer
2012-11-21 11:52     ` Hans Hagen
2012-11-21 12:28       ` Sietse Brouwer
2012-11-21 21:05     ` Acidrums4
2012-11-21 23:47       ` Sietse Brouwer
2012-11-22  0:03         ` Acidrums4
2012-11-22 10:55           ` Mojca Miklavec
2012-11-22 12:11             ` Sietse Brouwer
2012-11-23 20:50             ` Marcin Borkowski
2012-11-23 22:46               ` Hans Hagen
2012-11-23 23:09                 ` Alan BRASLAU
2012-11-22 10:04         ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50ACAC69.9060603@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).