A Filter Question: "Fullname, F. M."

I am looking for the shortest and yet efficient filter to get a name in two or three parts like “Silva Coper Boroni” and display it as “Boroni, S. C.”.
In another words an input like Firstname Middlename Famillyname shall be displayed in form of Famillyname, F. M.

I am using the below solution, but I think it is not a good one

<$vars author="Silva Coper Boroni">
 <$set name=authorname filter="[<author>split[ ]!is[blank]]">
<$text text={{{[enlist<authorname>last[]]}}} />,
<$list filter="[enlist<authorname>butlast[]]" variable=part>
<$text text={{{[<part>split[]]}}}/>.
</$list>
</$set>
</$vars>

I know nothing about how this is implemented… but would have thought it’s been addressed by CSL (About) used by Zotero and Mendeley… so wonder whether the general methodology, rather than the code itself, might be useful.

A

I found a more compressed solution, thanks to :map filter run prefix operator and $let widget.

<$let author="Silva Coper Boroni"
      last=     {{{ [<author>split[ ]last[]] }}}
      initials= {{{ [<author>split[ ]butlast[]] :map[split[]first[]addsuffix[.]] +[join[ ]] }}}
      dispname= {{{ [<last>addsuffix[, ]addsuffix<initials>]  }}}
>

<<dispname>>
</$let>

produces: Boroni, S. C.

Edited: Improved based on tw-Fred suggestion.

1 Like

In the :map filter run the {!!title} shouldn’t be needed. I tested quickly and it can be removed:

initials= {{{ [<author>split[ ]butlast[]] :map[split[]first[]addsuffix[.]] +[join[ ]] }}}

Fred