From: Wolfgang Schuster <wolfgang.schuster.lists@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: consistent index entries
Date: Sat, 1 Aug 2020 21:30:47 +0200 [thread overview]
Message-ID: <673719ec-6fba-04db-2cae-ffb14128f827@gmail.com> (raw)
In-Reply-To: <5545C586-7920-4865-A0D9-BD3C0E1BE405@fiee.net>
Henning Hraban Ramm schrieb am 01.08.2020 um 20:49:
>
>
>> Am 01.08.2020 um 13:22 schrieb Henning Hraban Ramm <texml@fiee.net>:
>>
>> Hi,
>>
>> besides the CG journal I’m working on a scientific biography with huge person and locality indexes (named Person and Locality for the examples).
>>
>> In many cases, the author wants additional information in the index, e.g.
>>
>> \Locality{Altona (Hamburg)}
>> \Locality{Breslau (pol. Wrocław)}
>> or
>> \Person{Arends, Katharina (née Schoemaker)}
>> \Person{Wilhelm II. (Kaiser)}
>>
>> Now, I need that consistent and I don’t want to type these complicated entries every time.
>>
>> I’m looking for a good way to handle this – maybe a lookup table in Lua, so that
>> \LookupPerson{Willy II}
>> would call a Lua function that returns
>> \Person{Wilhelm II. (Kaiser)}
>> ?
>>
>> Or is there already something in place that I overlooked, like
>> \OverwriteIndexEntry{Hraban}{Ramm, Henning Hraban}
>> ?
>
> I came up with:
>
> \startluacode
> user.Lookups = {
> ["Albano"] = "Albano (Provinz Rom)",
> ["Altona"] = "Altona (Hamburg)",
> ["Aurich"] = "Aurich (Ostfriesland)"
> }
>
> function user.Lookup(Name)
> local Res = user.Lookups[Name]
> if Res then
> return context(Res)
> else
> return context(Name)
> end
> end
> \stopluacode
>
> \def\Ort#1{\index{\ctxlua{user.Lookup("#1")}}}
You have to expand the \index argument:
\define[1]\Ort{\expanded{\index{...}}}
> \starttext
>
> \Ort{Albano}
> \Ort{Altona}
> \Ort{Aurich}
> \strut\page
>
> \placeindex
>
> \stoptext
>
>
> The lookup works so far, but all the entries get sorted unter C (because of \ctxlua).
>
> I remember I had the same problem with other macros (like \index{\emph{bla}}), but can’t find a solution in my usual sources.
When you use formatting commands etc. you have to use the optional
argument for sorting.
You can avoid a few problems when you move the \index command to Lua and
use context.index or you use a pure TeX solution.
%%%% begin lua example
\startluacode
userdata = userdata or { }
userdata.lookup = {
["Albano"] = "Albano (Provinz Rom)",
-- ["Altona"] = "Altona (Hamburg)",
["Aurich"] = "Aurich (Ostfriesland)"
}
function userdata.index(name)
local indexentry = userdata.lookup[name] or name
context.index(indexentry)
end
\stopluacode
\define[1]\Ort{\ctxlua{userdata.index("#1")}}
\starttext
\Ort{Albano}
\Ort{Altona}
\Ort{Aurich}
\dontleavehmode\page
\placeindex
\stoptext
%%%% end lua example
%%%% begin tex example
\setvariables
[index]
[Albano={Albano (Provinz Rom)},
%Altona={Altona (Hamburg)},
Aurich={Aurich (Ostfriesland)}]
\define[1]\Ort
{\doifelsevariable{index}{#1}
{\expanded{\index{\getvariable{index}{#1}}}}
{\index{#1}}}
\starttext
\Ort{Albano}
\Ort{Altona}
\Ort{Aurich}
\dontleavehmode\page
\placeindex
\stoptext
%%%% end tex example
Wolfgang
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2020-08-01 19:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-01 11:22 Henning Hraban Ramm
2020-08-01 18:49 ` Henning Hraban Ramm
2020-08-01 19:01 ` Jairo A. del Rio
2020-08-01 19:18 ` Jairo A. del Rio
2020-08-01 19:50 ` Henning Hraban Ramm
2020-08-01 19:30 ` Wolfgang Schuster [this message]
2020-08-01 20:16 ` Henning Hraban Ramm
2020-08-01 20:44 ` Wolfgang Schuster
2020-08-01 20:57 ` Henning Hraban Ramm
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=673719ec-6fba-04db-2cae-ffb14128f827@gmail.com \
--to=wolfgang.schuster.lists@gmail.com \
--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).