Lars Hellström <[log in to unmask]> writes:
> \@fancyfor\@tempa:=<list>\do{\@tempa}{, \@tempa}{ and \@tempa}
> and for <list> equal to A; A,B; A,B,C; A,B,C,D respectively get the results
> A
> A and B
> A, B and C
> A, B, C and D
As it happens I was working on similar functionality recently for the
amsrefs package (ftp://ftp.ams.org/pub/tex/amsrefs.zip). The package has
a \PrintSeries function used to print author names in a bibliography
when the data is a list of names in the form
\name{Downes, Michael}\name{Hellström, Lars}...
For AMS conventions your first/middle/last approach is not quite
adequate because cases 2 and 3 must be printed as
A and B
A, B, and C (Note the extra comma.)
And there are some other complications, as explained in the following
commentary from amsrefs.dtx:
% The \cn{PrintSeries} command prints a list of objects in series
% form. The essential idea is to produce something like \qq{A, B, and
% C} when we are given three elements A B C, with suitable variations
% in the punctuation and other intervening material if the number of
% elements is less or more than three.
%
% To generalize this process, we envision \cn{PrintSeries} being
% called as
%\PrintSeries{i0}{i1}{i2}{i3}{i4}{\do{A}\do{B}...}
% where i0, \dots, i4 are material to be interpolated and the last
% arg is a list of indeterminate length where each element consists
% of a macro and its argument. The output, depending on the number of
% elements, will be
% i0 A i4 % 1 element
% i0 A i1 B i4 % 2 elements
% i0 A i2 B i3 C i4 % 3 elements
% i0 A i2 B i2 C i2 ... X i2 Y i3 Z i4 % 26 elements
% That is the simple explanation but in practice there are some
% additional complications. What if user-supplied line breaks have to
% be supported at the boundaries between elements? What if in
% addition to adding material between elements we also want to apply
% some handy function to each element (e.g., \cn{textsc})? Even
% worse, what if we want the function to be different depending on
% the position of the element in the list?? Indeed if this did not
% happen to be the case with the current application I would not have
% gone to the extra trouble of supporting it. But if it must be so,
% then the output that we need from a list \verb'\do{A}\do{B}...' is
% f0{A}
% f0{A} p1 i1 f1{B}
% f0{A} p2 i2 f2{B} p3 i3 f3{B}
% and so on, where
% \begin{itemize}
% \item $f_n$ is a macro taking one argument,
% \item $p_n$ is punctuation\mdash material that must precede a line
% break if one occurs at this boundary,
% \item $i_n$ other interpolated material, as before.
% \end{itemize}
% To reduce the number of distinct required objects we decree that
% each element will get braces wrapped around it as a matter of
% course; then it is possible for f1, f2, f3 to be assimilated into
% the tail end of i1, i2, i3.
|