Re: [NTG-context] consistent index entries

2020-08-01 Thread Henning Hraban Ramm

> Am 01.08.2020 um 22:44 schrieb Wolfgang Schuster 
> :
>>> \define[1]\Ort{\expanded{\index{...}}}
>> Ah, I never know where to expand (tried \expanded\ctxlua).
> 
> \expanded needs a argument, i.e. \expanded{...}

I recognized it doesn’t work otherwise. But I thought TeX would always use the 
next token? Isn’t a command (or its result?) such a token?

>>> When you use formatting commands etc. you have to use the optional argument 
>>> for sorting.
>> I don’t understand.
>> \Ort[kursiv->]{Hamburg} works.
> 
> You mentioned only \index{\emph{...}} in your mail ...

I tried to simplify and couldn’t remember which command I needed when I had the 
\index{\something} problem (probably something similar, i.e. a self defined 
command that changed the text of the index entry). 

>>>  begin tex example
>> Oh, this is also nice. But isn’t the Lua version faster? (I have >600 person 
>> entries and a few hundred locations).
> 
> Hard to say without testing but the difference can be ignored because \index 
> itself is what take processing time.

Ok, thank you!

Hraban
___
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
___


Re: [NTG-context] consistent index entries

2020-08-01 Thread Wolfgang Schuster

Henning Hraban Ramm schrieb am 01.08.2020 um 22:16:



Am 01.08.2020 um 21:30 schrieb Wolfgang Schuster 
:

\def\Ort#1{\index{\ctxlua{user.Lookup("#1")}}}


You have to expand the \index argument:

\define[1]\Ort{\expanded{\index{...}}}


Ah, I never know where to expand (tried \expanded\ctxlua).


\expanded needs a argument, i.e. \expanded{...}


Now,

\def\TOrt#1{\expanded{\Ort{\ctxlua{userdata.Lookup("#1")}}}#1} % Loc + Text
\defineprocessor[kursiv][style=italicface]
\def\TFOrt#1{\expanded{\Ort[kursiv->]{\ctxlua{userdata.Lookup("#1")}}}#1} % Loc 
in Footnote + Text

works. :)

(I always define \TIndex to avoid doubling, e.g. Hamburg\index{Hamburg}.)



When you use formatting commands etc. you have to use the optional argument for 
sorting.


I don’t understand.

\Ort[kursiv->]{Hamburg} works.


You mentioned only \index{\emph{...}} in your mail ...


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

function userdata.index(name)
local indexentry = userdata.lookup[name] or name
context.index(indexentry)
end


That’s nice, but since I use different registers, I’d need to define that 
function for each. Since I also use several shortcuts (e.g. \TOrt, \TFOrt, 
\TPerson, \TFPerson) I would multiply the effort on the Lua side.
I find my TeX definitions (like above) shorter, where I can use the same Lua 
function for each.
With your code I could at least shorten it to:

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


 begin tex example


Oh, this is also nice. But isn’t the Lua version faster? (I have >600 person 
entries and a few hundred locations).



Hard to say without testing but the difference can be ignored because 
\index itself is what take processing time.


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
___


Re: [NTG-context] consistent index entries

2020-08-01 Thread Henning Hraban Ramm

> Am 01.08.2020 um 21:30 schrieb Wolfgang Schuster 
> :
>> \def\Ort#1{\index{\ctxlua{user.Lookup("#1")}}}
> 
> You have to expand the \index argument:
> 
> \define[1]\Ort{\expanded{\index{...}}}

Ah, I never know where to expand (tried \expanded\ctxlua).

Now,

\def\TOrt#1{\expanded{\Ort{\ctxlua{userdata.Lookup("#1")}}}#1} % Loc + Text
\defineprocessor[kursiv][style=italicface]
\def\TFOrt#1{\expanded{\Ort[kursiv->]{\ctxlua{userdata.Lookup("#1")}}}#1} % Loc 
in Footnote + Text

works. :)

(I always define \TIndex to avoid doubling, e.g. Hamburg\index{Hamburg}.)


> When you use formatting commands etc. you have to use the optional argument 
> for sorting.

I don’t understand.

\Ort[kursiv->]{Hamburg} works.

> 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
> 
> function userdata.index(name)
>local indexentry = userdata.lookup[name] or name
>context.index(indexentry)
> end

That’s nice, but since I use different registers, I’d need to define that 
function for each. Since I also use several shortcuts (e.g. \TOrt, \TFOrt, 
\TPerson, \TFPerson) I would multiply the effort on the Lua side.
I find my TeX definitions (like above) shorter, where I can use the same Lua 
function for each.
With your code I could at least shorten it to:

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

>  begin tex example

Oh, this is also nice. But isn’t the Lua version faster? (I have >600 person 
entries and a few hundred locations).

Thank you!

Hraban

___
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
___


Re: [NTG-context] consistent index entries

2020-08-01 Thread Henning Hraban Ramm


> Am 01.08.2020 um 21:01 schrieb Jairo A. del Rio :
> 
> Hi, Henning. According to the garden, something like:
> 
> \def\Ort#1{\index[#1]{\ctxlua{user.Lookup("#1")}}}
> 
> as long as #1 is capable of being sorted in the normal way, should work. 

Thank you, but that doesn’t work if my lookup e.g. creates 
"Garmisch-Partenkirchen" from "Partenkirchen".

> Am 01.08.2020 um 21:18 schrieb Jairo A. del Rio :
> 
> Wrt formatting (e.g. \index{\emph{something}}), the garden also mentions 
> processors for MkIV (https://wiki.contextgarden.net/Registers#Processors), so 
> you can wrap them with custom commands, in case it helps.

I already use processors; \emph was just an example.


Hraban
___
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
___


Re: [NTG-context] consistent index entries

2020-08-01 Thread Wolfgang Schuster

Henning Hraban Ramm schrieb am 01.08.2020 um 20:49:




Am 01.08.2020 um 13:22 schrieb Henning Hraban Ramm :

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
___


Re: [NTG-context] consistent index entries

2020-08-01 Thread Jairo A. del Rio
Wrt formatting (e.g. \index{\emph{something}}), the garden also mentions
processors for MkIV (https://wiki.contextgarden.net/Registers#Processors),
so you can wrap them with custom commands, in case it helps.

Cordially,

Jairo.

El sáb., 1 de ago. de 2020 a la(s) 14:01, Jairo A. del Rio (
jairoadelr...@gmail.com) escribió:

> Hi, Henning. According to the garden, something like:
>
> \def\Ort#1{\index[#1]{\ctxlua{user.Lookup("#1")}}}
>
> as long as #1 is capable of being sorted in the normal way, should work.
>
> Regards,
>
> Jairo
>
> El sáb., 1 de ago. de 2020 a la(s) 13:49, Henning Hraban Ramm (
> te...@fiee.net) escribió:
>
>>
>>
>> > Am 01.08.2020 um 13:22 schrieb Henning Hraban Ramm :
>> >
>> > 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")}}}
>>
>> \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.
>>
>>
>> Hraban
>>
>>
>> ___
>> 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
>>
>> ___
>>
>
___
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
___


Re: [NTG-context] consistent index entries

2020-08-01 Thread Jairo A. del Rio
Hi, Henning. According to the garden, something like:

\def\Ort#1{\index[#1]{\ctxlua{user.Lookup("#1")}}}

as long as #1 is capable of being sorted in the normal way, should work.

Regards,

Jairo

El sáb., 1 de ago. de 2020 a la(s) 13:49, Henning Hraban Ramm (
te...@fiee.net) escribió:

>
>
> > Am 01.08.2020 um 13:22 schrieb Henning Hraban Ramm :
> >
> > 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")}}}
>
> \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.
>
>
> Hraban
>
>
> ___
> 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
>
> ___
>
___
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
___


Re: [NTG-context] consistent index entries

2020-08-01 Thread Henning Hraban Ramm


> Am 01.08.2020 um 13:22 schrieb Henning Hraban Ramm :
> 
> 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")}}}

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


Hraban

___
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
___


[NTG-context] consistent index entries

2020-08-01 Thread Henning Hraban Ramm
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)}
\Locallity{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}
?

Hraban
___
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
___