[NTG-context] Fwd: Custom sorting of "pseudo-language" in a register

Hans Hagen j.hagen at xs4all.nl
Thu Mar 22 19:50:57 CET 2018


On 3/22/2018 9:25 AM, luigi scarso wrote:
> ---------- Forwarded message ----------
> From: John Grasty <johnpgrasty at gmail.com>
> Date: Fri, Mar 16, 2018 at 4:15 PM
> Subject: [NTG-context] Custom sorting of "pseudo-language" in a register
> To: mailing list for ConTeXt users <ntg-context at ntg.nl>
> 
> 
> Hello all,
> 
> I’m just getting acquainted with ConTeXt, and I am finding it so much
> more suitable for my work and needs. Thanks for the great software.
> Here’s my situation. I write in Slovene and in English, and I need to
> make numerous references to biblical passages. I want to create an
> index of these citations, but I want them in the order they appear in
> the Bible rather than alphabetical order. Henri Menke provided a
> perfectly workable solution on TeX StackExchange[^1], but because this
> is a multi-year project, I wanted to find a bit more permanent
> solution. I discovered I can use Lua LPEG to parse and normalize my
> citations so they are referenced in a uniform style.
> 
> My problem comes in the register sorting. Hans, I saw where in the
> paste you have recommended a “pseudo-language” to implement a custom
> sort in such a situation. I have almost figured out how to accomplish
> this. (See the MWE below.) I have no problem with single word sections
> (Genesis, Exodus, etc.). I can turn off indicators, do the custom sort
> (see below), and I get the intended result. If I have a multiple word
> title (Evangelij po Janezu), that technique doesn’t work. The
> replacement for more than one word (or if a number is involved, like
> 1John) doesn’t seem to work. I have no doubt there is a good reason;
> I’m just a newbie!
> 
> It seems my options are to:
> 
> 1. Figure out how to do a replacement for a phrase or a book with a
> number in its name. Then this technique seems to work ok.
> 2. Or to add an entries and figure out some way to not print the first
> level in the index. So the indicator will be the book name, and
> underneath the chapter and verses will be listed with out the book
> name being repeated.
> 
> 
> Are there any ideas to point me in the right direction?

You're bitten by the cleaner that kind of normalizes entries as you can 
see when you say

\enabletrackers[*sort*]

replacing spaces by \0 can help but that sort of assumes that you know 
what happens inside

So, i added some code to handle that. I also added a helper so that you 
can do:

\startluacode
     local list = {
         -- old testament
         "Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy", 
"Joshua",
         "Judges", "Ruth", "1 Samuel", "2 Samuel", "1 Kings", "2 Kings",
         "1 Chronicles", "2 Chronicles", "Ezra", "Nehemiah", "Esther", 
"Job", "Psalms",
         "Proverbs", "Ecclesiastes", "Canticles", "Isaiah", "Jeremiah",
         "Lamentations", "Ezekiel", "Daniel", "Hosea", "Joel", "Amos", 
"Obadiah",
         "Jonah", "Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", 
"Zechariah",
         "Malachi",
         -- new testament
         "Matthew", "Mark", "Luke", "John", "Acts", "Romans", "1 
Corinthians",
         "2 Corinthians", "Galatians", "Ephesians", "Philippians", 
"Colossians",
         "1 Thessalonians", "2 Thessalonians", "1 Timothy", "2 Timothy", 
"Titus",
         "Philemon", "Hebrews", "James", "1 Peter", "2 Peter", "1 John", 
"2 John",
         "3 John", "Jude", "Revelation",
     }

     sorters.definitions['bbt'] = {
         replacements = sorters.replacementlist(list),
     }
\stopluacode

\defineregister
   [booksort]
   [language=bbt,
    n=1,
    indicator=no]

\starttext

     One   \booksort{Genesis+5.2}
     Two   \booksort{Exodus+2}
     Three \booksort{Genesis+45}
     Four  \booksort{Philemon+2}
     Five  \booksort{John+45}
     Six   \booksort{1 John 1+45}
     Seven \booksort{2 John 2+45}

     \blank[3*line]

     \placeregister[booksort][language=bbt]

\stoptext

It probably makes sense to make this into a module but then we need to 
collect a few lists.

I'll upload a beta.

Hans

> Thanks so much for your help,
> John Grasty
> 
> 
> 
> [1]: https://tex.stackexchange.com/questions/418575/custom-ordering-for-a-index-register-in-context/
> 
> - - - -
> 
> \startluacode
> 
> local utfchar, utfbyte  = utf.char, utf.byte
> local sorters           = sorters
> local definitions       = sorters.definitions
> local replacementoffset = sorters.constants.replacementoffset
> local variables         = interfaces.variables
> 
> local gen  = utfchar(replacementoffset + 1), utfchar(replacementoffset + 11)
> local exo = utfchar(replacementoffset + 2), utfchar(replacementoffset + 220)
> local jn = utfchar(replacementoffset + 4), utfchar(replacementoffset + 27)
> 
> 
> sorters.definitions['bbt'] = {
>      replacements = {
>          { "Geneza", gen },
>          { "Eksodus", exo },
>          { "Janez", jn },
>          },
> 
>      orders = {
>          gen, exo, jn
>      }
> }
> \stopluacode
> 
> \mainlanguage[sl]
> 
> \defineregister[booksort]
> \setupregister[booksort]
>   [language=bbt,
>    n=1,
>    indicator=yes,
>    ]
> 
> 
> \starttext
> 
> \booksort{Janez+5.2}One
> \booksort{Eksodus+2}Two
> \booksort{Geneza+45}Three
> 
> \page
> 
> \placeregister[booksort][language=bbt]
> 
> \stoptext
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry
> to the Wiki!
> 
> maillist : ntg-context at ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
> 
> 


-- 

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the ntg-context mailing list