[tex-eplain] optional arguments

John Culleton john at wexfordpress.com
Mon Mar 23 17:38:01 CET 2009


On Monday 23 March 2009 08:10:27 am Adam Fenn wrote:
> > I don't understand -- how can the order be wrong if the
> > names are all the same? :)  But if you mean, relative
> > to other ("non-architect") entries, then the problem is
> > again with non-expanding \name, because makeindex sorts
> > the string "\name" instead of what this macro stands
> > for.
> >
> > \makeatletter
> >
> > \newtoks\arch at name
> > \newtoks\arch at loc
> >
> > \def\architect#1{%
> >   \arch at name={#1}%
> >   \@getoptionalarg\finisharchitect
> > }
> >
> > \def\finisharchitect{%
> >   \arch at loc=\expandafter{\@optionalarg}%
> >   \ifx\@optionalarg\empty
> >     % No optional argument present.
> >     \expandafter\sidx\expandafter{\the\arch at name}
> >   \else
> >     % One was present.
> >     \edef\temp{architects!\the\arch at name, {\noexpand\it
> > \the\arch at loc}}% \expandafter\sidx\expandafter{\temp}%
> >     \edef\temp{\the\arch at name, {\noexpand\it architect,
> > \the\arch at loc}}% \expandafter\sidx\expandafter{\temp}%
> >   \fi
> > }
> >
> > \resetatcatcode
>
> I've just noticed that there is something not quite right
> here.
>
> If you run TeX on
>
> \architect{Smith, John}
>
> \architect{Smith}
>
> the index is correctly typeset as
>
> Smith, 1
> Smith, John, 1
>
> However, if you include the optional argument
>
> \architect{Smith, John}[London]
>
> \architect{Smith}[London]
>
> then the index is incorrectly typeset
>
> Smith, John, architect, of London, 1
> Smith, architect, of London
>
> Any ideas how I can sort this out?
>
> TIA
> Adam.
I also note that these two entries will end up as separate 
items in the index:
\idx{Smith, John}
\idxname{John}{Smith}

So I use one form or the other in the entire document. 


-- 
John Culleton
Able Indexers and Typesetters
http://wexfordpress.com


More information about the tex-eplain mailing list