ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Is there a short-cut to adding sub-categories for index entries?
       [not found] <492249429.6335628.1724593083943.ref@mail.yahoo.com>
@ 2024-08-25 13:38 ` Joel via ntg-context
  2024-08-25 14:29   ` [NTG-context] " Henning Hraban Ramm
  0 siblings, 1 reply; 2+ messages in thread
From: Joel via ntg-context @ 2024-08-25 13:38 UTC (permalink / raw)
  To: Mailing List for ConTeXt Users; +Cc: Joel


[-- Attachment #1.1: Type: text/plain, Size: 1572 bytes --]

 
I have a document with thousands of index entries. Here’s a samplecode:




\starttext

 Some people livedin \index{cliff-dwelling}cliff-dwellings, while others lived in\index{lean-to}lean-tos.




\placeindex

\stoptext




This produces anindex like this:







c

cliff-dwelling 1







 l

 lean-to 1




I’d like to createan index with much more sub-categories to find the same entries, forinstance, a category of “dwellings”:




c

cliff-dwelling 1







d

dwellings

 cliff-dwelling 1

 lean-to 1




 l

 lean-to 1




As I’m aware, theway to code this is as follows:

\starttext

 Some people livedin\index{cliff-dwelling}\index{dwellings+cliff-dwelling}cliff-dwellings,while others lived in\index{lean-to}\index{dwellings+lean-to}lean-tos.




\placeindex

\stoptext



I’m wondering ifthere is a short-cut means to set this up, such that if I can tellthe document that any time it sees “cliff-dwellings” in an index,it will also add its page numbers to under “dwellings+cliff-dwelling”? In other words, is there an easierway to add these categories, then to go through the entire documentand mark them? I already have a list of all the words. 
For instance, in my above code, I must find every \index{cliff-dwelling} entry and add a \index{dwellings+cliff-dwelling} next to it...which would take hundreds of hours if I did that for every word. Is there a quicker way to tell it always also add it under "dwellings" too?




--Joel


[-- Attachment #1.2: Type: text/html, Size: 4325 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [NTG-context] Re: Is there a short-cut to adding sub-categories for index entries?
  2024-08-25 13:38 ` [NTG-context] Is there a short-cut to adding sub-categories for index entries? Joel via ntg-context
@ 2024-08-25 14:29   ` Henning Hraban Ramm
  0 siblings, 0 replies; 2+ messages in thread
From: Henning Hraban Ramm @ 2024-08-25 14:29 UTC (permalink / raw)
  To: ntg-context

Am 25.08.24 um 15:38 schrieb Joel via ntg-context:
> I have a document with thousands of index entries. Here’s a sample code:
> Some people lived in 
> \index{cliff-dwelling}\index{dwellings+cliff-dwelling}cliff-dwellings, 
> while others lived in \index{lean-to}\index{dwellings+lean-to}lean-tos.

> 
> I’m wondering if there is a short-cut means to set this up, such that if 
> I can tell the document that any time it sees “cliff-dwellings” in an 
> index, it will also add its page numbers to under 
> “dwellings+cliff-dwelling”? In other words, is there an easier way to 
> add these categories, then to go through the entire document and mark 
> them? I already have a list of all the words.
> 
> For instance, in my above code, I must find every \index{cliff-dwelling} 
> entry and add a \index{dwellings+cliff-dwelling} next to it...which 
> would take hundreds of hours if I did that for every word. Is there a 
> quicker way to tell it always also add it under "dwellings" too?

If it’s just a few instances, define a macro:

\define[1]\DwIndex{\index{#1}\index{dwellings+#1}#1}

For a list of words, a lookup table and a Lua function make sense.

With a comparable problem, normalizing location names, I used this:

-- lookups.lua
userdata = userdata or { }

userdata.Mapping = {
   ["Albano"] = "Albano (Provinz Rom)",
   ["Altona"] = "Altona (Hamburg)",
   ["Aurich"] = "Aurich (Ostfriesland)",
-- …
}

function userdata.Lookup(name)
   context(userdata.Mapping[name] or name)
end


%%% environment

\loadluafile[lookups.lua]
\defineregister[Location][]
\define[1]\LocIndex{\expanded{\Location{%
   \ctxlua{userdata.Lookup("#1")}}}}


Hraban
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-25 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <492249429.6335628.1724593083943.ref@mail.yahoo.com>
2024-08-25 13:38 ` [NTG-context] Is there a short-cut to adding sub-categories for index entries? Joel via ntg-context
2024-08-25 14:29   ` [NTG-context] " Henning Hraban Ramm

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).