I have to format the bibliography data in many ways! One case is APA format as below!
Q1
A bibtex entry has a bibtex-author field, normally authors name are separated with and, I have to format the output
to mimic the real situation I give below an example.
\define results() $(first)$, and $(last)$
<$vars authorlist="Maarten R. Dobbelaere and Pieter P. Plehiers and Ruben Van de Vijver and Christian V. Stevens and Kevin M. Van Geem">
<$vars first={{{ [<authorlist>split[ and ]butlast[]join[, ]] }}} last={{{ [<authorlist>split[ and ]last[]] }}}>
-- <<results>>
</$vars>
</$vars>
<$vars authorlist="Maarten R. Dobbelaere and Pieter P. Plehiers and Ruben Van de Vijver and Christian V. Stevens and Kevin M. Van Geem"
replace1=" and "
replace2=",([^,]*)$"
>
<$vars first={{{ [<authorlist>search-replace:g:regexp<replace1>,[, ]search-replace:g:regexp<replace2>,[, and $1]]}}}
>
<<first>>
</$vars>
</$vars>
That’s true, the hard part is to show the author name as surname Initials , e.g. Nguyen, T., Carnevale, J. J., Scholer, A. A., Miele, D. B., & Fujita, K.
Assume a name like Ruben Van de Vijver where the last three words are surname!
Of course some bibtex generator uses Ruben {Van de Vijver}
This requires human knowledge. You would need a pre-process that analyzes standard known special forms (e.g. Van de xxxxxxx} and maybe converts them all into something like Van#de#xxxxxxx. After that you can run your process to convert first and middle names into initials. At the end you would convert “#” into spaces.
I chose “#” because I know of no name with that symbol. I did know someone with an apostrophe in her name, so punctuation can sometimes be part of names.
What do you think, if we process the {surname with space}? It seems bibtex uses {...} to indicate this is a multi words surname or a name which contains spaces!
If the source author list is already formatted for you, that should make things easier. But you’ll have to use some extra escaping in regexp because { } are used in regexp.