ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* HOWTO: Add index entries within a macro.
@ 2002-04-06  6:08 Daniel Pittman
  2002-04-06 14:13 ` John Culleton
  2002-04-07  9:46 ` Hans Hagen
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Pittman @ 2002-04-06  6:08 UTC (permalink / raw)


As part of the cookbook that I am working on, I have a fair bit of
information available as part of the typesetting process that I would
like to use to create automatic index (register)[1] entries.

So, given that I have these various bits of information available, I
would like to write information to the index automatically, placing
items for the dish in an alphabetical index, indexing by some major
ingredients or ingredient types and the like.

I tried \index{\Category+\RecipeTitle}, which didn't work -- the
indexing blew up because '\RecipeTitle' and '\Category' were unknown
control sequences.

Looking through 'core-reg.tex' didn't shed much light on it -- the few
things that looked like they might work were, unfortunately, prone to
exactly the same failure cases.

The only way I could find that actually worked was, in a minimal
example:

\def\MyTitle{Mango Bread} \def\MyCategory{Bread}
\edef\LocalDoIndex{\noexpand\index{\MyCategory+\MyTitle}}
\LocalDoIndex

I can obviously pretty that up a little by wrapping it into a
'ExpandedIndex' macro or such that will do the expansion, etc, and write
the final index note.

Is there a better way of achieving this result, though?

Finally, as a note on improving the documentation of ConTeXt, it would
be extremely helpful to include an entry in the manual index that would
direct people to 'registers' when they looked for 'index'. That would
have saved me some headache when I first went looking for them. :)

        Daniel

Footnotes: 
[1]  I use the English "index" name, not the (to me, at least) next to
     unknown "register" naming that the ConTeXt manual uses. 

-- 
I was twenty-five, and too old to be unusual.
        -- James D. Watson, _The Double Helix_, (1968)


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

* Re: HOWTO: Add index entries within a macro.
  2002-04-06  6:08 HOWTO: Add index entries within a macro Daniel Pittman
@ 2002-04-06 14:13 ` John Culleton
  2002-04-07  9:30   ` Hans Hagen
  2002-04-07  9:46 ` Hans Hagen
  1 sibling, 1 reply; 5+ messages in thread
From: John Culleton @ 2002-04-06 14:13 UTC (permalink / raw)


On Saturday 06 April 2002 01:08, Daniel Pittman wrote:
> As part of the cookbook that I am working on, I have a fair bit of
> information available as part of the typesetting process that I
> would like to use to create automatic index (register)[1] entries.
>
> So, given that I have these various bits of information available,
> I would like to write information to the index automatically,
> placing items for the dish in an alphabetical index, indexing by
> some major ingredients or ingredient types and the like.
>
> I tried \index{\Category+\RecipeTitle}, which didn't work -- the
> indexing blew up because '\RecipeTitle' and '\Category' were
> unknown control sequences.
>
> Looking through 'core-reg.tex' didn't shed much light on it -- the
> few things that looked like they might work were, unfortunately,
> prone to exactly the same failure cases.
>
> The only way I could find that actually worked was, in a minimal
> example:
>
> \def\MyTitle{Mango Bread} \def\MyCategory{Bread}
> \edef\LocalDoIndex{\noexpand\index{\MyCategory+\MyTitle}}
> \LocalDoIndex
>
The eplain.tex indexing macros + makeindex work well enough for
me to make money as an indexer :-) It may be possible to extract
them from plain.tex and input them into a Context run. (The entire
eplain.tex file has at least one incompatablity with Context, hence
I suggest a subset of it.) 
> I can obviously pretty that up a little by wrapping it into a
> 'ExpandedIndex' macro or such that will do the expansion, etc, and
> write the final index note.
>
> Is there a better way of achieving this result, though?
>
>
> Finally, as a note on improving the documentation of ConTeXt, it
> would be extremely helpful to include an entry in the manual index
> that would direct people to 'registers' when they looked for
> 'index'. That would have saved me some headache when I first went
> looking for them. :)
>
>         Daniel
>
> Footnotes:
> [1]  I use the English "index" name, not the (to me, at least) next
> to unknown "register" naming that the ConTeXt manual uses.

In your case, instead of using e.g.,  \Category perhaps the indexing
could be wrapped up in a macro that put the value of \Category in the 
indexing command. Can you use something like \the\Category? 

Yes, an index is an index and a register is something that holds a
number, in my English at least.  Perhaps Hans Hagen will accomodate
your request in the next update of  his amazing manual. It is, after 
all, much more readable even in translation than ``The TeXBook'' :-)

-- 
John Culleton, john@wexfordpress.com
   Able Indexers and Typesetters
      http://wexfordpress.com
<------------------------------------>
This Linux system at  9:13am  up 24 days 22 hrs 27 mins


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

* Re: HOWTO: Add index entries within a macro.
  2002-04-06 14:13 ` John Culleton
@ 2002-04-07  9:30   ` Hans Hagen
  0 siblings, 0 replies; 5+ messages in thread
From: Hans Hagen @ 2002-04-07  9:30 UTC (permalink / raw)
  Cc: ntg-context

At 09:13 AM 4/6/2002 -0500, you wrote:

> > [1]  I use the English "index" name, not the (to me, at least) next
> > to unknown "register" naming that the ConTeXt manual uses.

there used to be 'index' only, so when i made it general, i came up with 
register (can be a register of names, places, commands, topics, concepts, etc)

>number, in my English at least.  Perhaps Hans Hagen will accomodate

i'll do my best

btw, registers will be extended some day (for instance, there is already a 
method to replace page numbers by user supplied numbers)

hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                                   fall-back web server: 
www.pragma-ade.nl
-------------------------------------------------------------------------


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

* Re: HOWTO: Add index entries within a macro.
  2002-04-06  6:08 HOWTO: Add index entries within a macro Daniel Pittman
  2002-04-06 14:13 ` John Culleton
@ 2002-04-07  9:46 ` Hans Hagen
  2002-04-08  7:04   ` Daniel Pittman
  1 sibling, 1 reply; 5+ messages in thread
From: Hans Hagen @ 2002-04-07  9:46 UTC (permalink / raw)
  Cc: ntg-context

At 04:08 PM 4/6/2002 +1000, Daniel Pittman wrote:

>The only way I could find that actually worked was, in a minimal
>example:
>
>\def\MyTitle{Mango Bread} \def\MyCategory{Bread}
>\edef\LocalDoIndex{\noexpand\index{\MyCategory+\MyTitle}}
>\LocalDoIndex
>
>I can obviously pretty that up a little by wrapping it into a
>'ExpandedIndex' macro or such that will do the expansion, etc, and write
>the final index note.
>
>Is there a better way of achieving this result, though?

\starttext

\setupregister[index][expansion=yes]
\def\test{\bf test}

test\index{\test}

\stoptext

so,

in that case \index{\MyCategory+\MyTitle}

will be expanded

[expansion=yes] expands the index entry, but leaves macros defined as 
\unexpanded\def\... untouched, so most of the context commands will be 
passed as commands

[expansion=command] is another option, this gives a one level expansion

Hans
-------------------------------------------------------------------------
                                   Hans Hagen | PRAGMA ADE | pragma@wxs.nl
                       Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: +31 (0)38 477 53 69 | fax: +31 (0)38 477 53 74 | www.pragma-ade.com
-------------------------------------------------------------------------
                                   fall-back web server: 
www.pragma-ade.nl
-------------------------------------------------------------------------


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

* Re: HOWTO: Add index entries within a macro.
  2002-04-07  9:46 ` Hans Hagen
@ 2002-04-08  7:04   ` Daniel Pittman
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Pittman @ 2002-04-08  7:04 UTC (permalink / raw)


On Sun, 07 Apr 2002, Hans Hagen wrote:
> At 04:08 PM 4/6/2002 +1000, Daniel Pittman wrote:

[...]

>>I can obviously pretty that up a little by wrapping it into a
>>'ExpandedIndex' macro or such that will do the expansion, etc, and
>>write the final index note.
>>
>>Is there a better way of achieving this result, though?

[...]

> \setupregister[index][expansion=yes]

[...]

> [expansion=yes] expands the index entry, but leaves macros defined as
> \unexpanded\def\... untouched, so most of the context commands will be
> passed as commands
> 
> [expansion=command] is another option, this gives a one level
> expansion

Thanks. That does it very nicely. :)
        Daniel

-- 
The scenario of terrorism, then, as a mutating virus that copies itself to
American rage on its way to revenge against the host-scapegoat.
        -- Arthur and Marilouise Kroker, _Terrorism of Viral Power_


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

end of thread, other threads:[~2002-04-08  7:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-06  6:08 HOWTO: Add index entries within a macro Daniel Pittman
2002-04-06 14:13 ` John Culleton
2002-04-07  9:30   ` Hans Hagen
2002-04-07  9:46 ` Hans Hagen
2002-04-08  7:04   ` Daniel Pittman

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