[tex-eplain] optional arguments

Adam Fenn acwfenn at ntlworld.com
Mon Mar 30 14:00:39 CEST 2009


 > > It is wrong (I think) because of this part of the macro
 > >
 > > \edef\temp{\the\arch at name, {\noexpand\it architect, \the\arch at loc}}%
 > > \expandafter\sidx\expandafter{\temp}%
 > >
 > > which makeindex orders entries under {\it architect. If you remove 
the command to
 > > put the word architects in italics the index is typeset correctly.
 >
 > Removing "{\it" doesn't change anything for me. I see what you mean,
 > but makeindex actually works correctly. Consider this:
 >
 > architects
 > Smith, John, London, 1
 > Smith, London, 1
 >
 > Now, without the markup, you should see that the sorting is correct --
 > J sorts before L. What you want is a two-key sorting (author name as
 > the first key, location as the second), and makeindex doesn't support
 > that. You could use only author name as the sort key, but then the
 > entries might end up sorted wrong (or even merged?) when there are two
 > authors with the same name from different locations. Or you could
 > make location into a third-level key, but that would look ugly.


Oleg, you are looking at the wrong part of the index. The sub entries 
under
architect are sorted and printed correctly. It is the other two entries 
that are
the wrong way around i.e.

Smith, John, architect, London, 1
Smith, architect, London, 1

should be

Smith, architect, London, 1
Smith, John, architect, London, 1

It works correctly if you remove {\it ...} and you look at the correct 
part of the index,
which is why I wanted to know about this;


 > > Normally I would use something along the lines of
 > >
 > > \sidx{architect@{\it architect}}
 > >
 > > but I do not know how to insert this into the \architect macro so
 > > that it will work.
 >
 > I include the revised \finisharchitect below, even though it doesn't
 > help with your problem.

Yes it does!
It solves the problem, though the \noexpand seems redundant
and this approach does not seem necessary for the sub entries.

 > \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, \the\arch at loc
 > @\the\arch at name, {\noexpand\it \the\arch at loc}}%
 > \expandafter\sidx\expandafter{\temp}%
 > \edef\temp{\the\arch at name, architect, \the\arch at loc
 > @\the\arch at name, {\noexpand\it architect, \the\arch at loc}}%
 > \expandafter\sidx\expandafter{\temp}%
 > \fi
 > }

Thanks,
Adam.



More information about the tex-eplain mailing list