Abstracting an author list

I am writing an academic paper and have no problem manually formatting an author list like

\startnarrower[middle]
\startalignment[middle]
Author One\thanks{email_one@gmail.com},
Author Two\thanks{email_two@gmail.com},
Author Three\thanks{email_three@gmail.com}
\stopalignment
\stopnarrow


Of course, this is somewhat unsavory. It would be nice to abstract this structure to something like:

\author{Author One}{email_one@gmail.com}
\author{Author Two}{email_two@gmail.com}
\author{Author Three}{email_three@gmail.com}

\placeauthorlist


However, I have no idea how to implement such a structure. I've google and looked all over the ConTeXt wiki and cannot find much on it. Anyone know of some resources that might be of use or of a similar implementation?

Edit: I worked out a solutions that does what I need it to. I'm not sure how idiomatic it is and, seeing as how I have never written module code, have no idea if it is truly "correct", but it does produce the desired output.

If you can improve it in any way, please feel free to and I'll give you the answer.

-
If you are writing an academic paper for a journal, check the journal's instructions to authors (e.g., OUP specifies use of Word, RTF, Tex, or Latex) - if the journal supplies Latex class, you should use that and not Context. – Charles Stewart Nov 21 '12 at 10:02
I agree with Charles on this point. None of the popular publishers (at least in engineering) use ConTeXt. If the journal uses LaTeX, then it is better for you to submit the document in LaTeX rather than let the journal translate from ConTeXt to LaTeX. However, I still prefer using ConTeXt in the initial writing phase and translate the document to LaTeX on my own when I am done (usually takes about 2-4 hours). Now that I think of it, it may not be a bad idea to create a LaTeX backend for ConTeXt (similar to the XML backend). – Aditya Nov 22 '12 at 5:56

I would design the interface like this:

\defineauthor[john][name={John Doe}, email={john.doe@gmail.com}, affiliation={....}]
\defineauthor[jill][name=..., email=..., affiliation=...]

\setupdocument
[title={....},
authors={john, jill}]

\startdocument
....
\stopdocument


Note that ConTeXt already defines a \setupdocument and \startdocument ... \stopdocument command that are meant to handle document metadata. \startdocument calls \starttext and \stopdocument calls \stoptext, so you do not need to explicitly add them (although adding them does no harm). In order for the above setup to work you need to define:

\startsetups document:start
\documentvariable{title} % Use this to get the document title
\documentvariable{author} % Use this to get the list of authors
\stopsetups

\startsetups document:stop
% If you want to place something at the end of a document
\stopsetups


So, all that is left is to define the \defineauthor command. If you are using MkIV, you may simply use:

\definenamespace
[documentauthor] % name of internal varialbles
[type=module,
name=author,
command=yes, % Create \defineauthor
style=yes, % Create \useauthorstyleandcolor
setup=list, % Create \setupauthor
parent=documentauthor,
]


which will create the required command.

The above may appear like an overkill for adding authors, but it does provide you will the following features:

• Inherit keys across authors. Suppose you have multiple authors at the same institute, and you don't want to pass on the affiliation each time. Then you can do:

\defineauthor[univ1][afficiation={TeX University}]

\defineauthor[john][univ1][name=..., email=...]
\defineauthor[jill][univ1][name=..., email=...]


and both john and jill will inherit the affiliation from univ1.

• Create an author database: You can create an author database in a separate file and use

\environment author-database


in all your files. This way, you only define the authors once and can use them in all your documents.

EDIT: Here is a complete example:

\definenamespace
[documentauthor] % name of internal varialbles
[type=module,
name=author,
command=yes, % Create \defineauthor
style=yes, % Create \useauthorstyleandcolor
setup=list, % Create \setupauthor
parent=documentauthor,
]

\define[1]\useauthor
{\edef\currentauthor{#1}%
{\useauthorstyleandcolor{style}{color}
\authorparameter{name}}%
\space
(\mono{\authorparameter{email}})}

\startsetups document:start
\startalignment[middle]
{\ssbfc\setupinterlinespace
\documentvariable{title}
\endgraf}
\blank[medium]
\processcommacommand[\documentvariable{author}]\useauthor
\blank[big]
\stopalignment
\stopsetups

\startsetups document:stop
% If you want to place something at the end of a document
\stopsetups

\setupauthor[style=sansbold]

\defineauthor[john][name={John Doe}, email={john.doe@gmail.com}]
\defineauthor[jill][name={Jill Doe}, email={jill.doe@gmail.com}]

\setupdocument[title={Random title}, author={john,jill}]

\startdocument
\input knuth
\stopdocument

-
I'm working on implementing that, but I don't seem to be making any headway. The code which you provided doesn't produce any output for me. Do know of any resources on \setups and namespaces? I've looked over the ConTeXt wiki, but haven't found too much. – Doug Moore Nov 23 '12 at 4:09
Sorry, I made a mistake in my answer. The setups should be document:start and document:stop rather than document:before and document:after. I edited the question to correct it. – Aditya Nov 23 '12 at 7:28
Namespaces are explained on the ConTeXt wiki. I'll add a page on setups as well. – Aditya Nov 23 '12 at 7:32
I found that page, but once you use \defineauthor[john][name={...}] how do you actually display the information? Your example simply displays the authors as "john, jill". – Doug Moore Nov 23 '12 at 20:49
I have added a complete example. Once you have the list of authors, you need to go over them (\processcommacommand) and then individually format each of those (for which I defined a \useauthor command that uses \authorparameter to access the parameters like name and email of the author). – Aditya Nov 23 '12 at 23:42

So, I figured out how to get an author list to work as above; however, I am not sure that it is idiomatic ConTeXt:

\unprotect

\newcount\authcount
\authcount0\relax

\expandafter\def\csname getauthor\the\authcount\endcsname{#1}
\expandafter\def\csname getemail\the\authcount\endcsname{#2}}

\define[1]\putauthor{\csname getauthor#1\endcsname\thanks{\csname getemail\recurselevel\endcsname}}

\define[]\placeauthors{
\startnarrower[middle]
\startalignment[middle]
\doloop{
\ifnum\recurselevel<\authcount
\ifnum\recurselevel>1
\mbox{\putauthor{\recurselevel}},
\else
\putauthor{\recurselevel},
\fi
\else \exitloop \fi
}
\ifnum\authcount>1 and
\mbox{\putauthor{\the\authcount}}
\else
\putauthor{\the\authcount}
\fi
\stopalignment
\stopnarrower
}
\protect


To use it:

\author{Name One}{email_one@gmail.com}
\author{Name Two}{email_two@gmail.com}
\author{Name Three}{email_three@gmail.com}
\author{Name Four}{email_four@gmail.com}

\placeauthors


Which will generate the following output (though the conversion set for your \thanks command may change the footnote symbols):

Name One∗, Name Two†, Name Three‡, and Name Four∗∗


centered on the page with email addresses in the footnotes.

I hope this helps someone other than me.

-
Note that instead of \mbox, it may be better to use \framed. You can use \defineframed[authorframed][frame=off,foregroundstyle=..., foregroundcolor=...] and then use \authorframed{...} and get the ability to set the author style and color for free. – Aditya Nov 22 '12 at 5:52
@Aditya Thanks for the advice. I considered using \framed` but didn't because it made the code longer. Really, that bit of code is there to prevent a newline in the middle of an authors name. I'll probably change that. – Doug Moore Nov 22 '12 at 17:32