5

I would like to store each authors firstname, initials and lastname values in newcommands. My MWE is:

\documentclass{article}
\usepackage{xparse}
\makeatletter
\def\author#1{\gdef\@author{#1}
\getfirstpart\firstname{#1}
%\getinitial\initials{#1}
\getlastpart\lastname{#1}}
\makeatother

\ExplSyntaxOn
\NewDocumentCommand{\getfirstpart}{mm}
 {
  \seq_set_split:Nnn \l_tmpa_seq { ~ } { #1 }
  \seq_pop_left:NN \l_tmpa_seq #1
 }

\NewDocumentCommand{\getlastpart}{mm}
 {
  \seq_set_split:Nnn \l_tmpa_seq { ~ } { #2 }
  \seq_pop_right:NN \l_tmpa_seq #1
 }
\ExplSyntaxOff

\begin{document}
\author[[email protected], web="http://www.tex.stackexchange.com", address=Department of Mathematics, UK]{John Smith} %% mail value should store \mail{[email protected]}, web value should store in \web{http://www.tex.stackexchange.com} and address value should store \address{Department of Mathematics, UK}

\firstname and \lastname

\author{John X. Smith}
\firstname and \lastname %%how do store initial value?

\author{Smith}

\author{Brian H.-K. Lly}

\end{document}
3
  • The last example shows that it's hard to automate every case, as the first name is “Brian”, while the family name is ”Hamilton Kelly”.
    – egreg
    Sep 4, 2013 at 10:29
  • @egreg I have updated the questions and \author{Brian H.-K. Lly} it's possible to automate?
    – Balaji
    Sep 4, 2013 at 10:32
  • I've had a go at this in some experimental code, but with a rather more 'rich' interface. At present, we are lacking a good storage mechanism for the data, plus there is still interface discussion to have. See github.com/latex3/svn-mirror/tree/master/l3trial/xmetadata.
    – Joseph Wright
    Sep 4, 2013 at 11:32

1 Answer 1

5

For standard American names “Firstname I. Surname” automation is possible. Here's some code that uses this, but can be helped for different cases:

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\keys_define:nn { balaji/author }
 {
  mail .tl_set:N = \l_balaji_mail_tl,
  mail .initial:n = {},
  web .tl_set:N = \l_balaji_web_tl,
  web .initial:n = {},
  address .tl_set:N = \l_balaji_address_tl,
  address .initial:n = {},
  firstname .tl_set:N = \l_balaji_firstname_tl,
  firstname .initial:n = {},
  initials .tl_set:N = \l_balaji_initials_tl,
  initials .initial:n = {},
  lastname .tl_set:N = \l_balaji_lastname_tl,
  lastname .initial:n = {},
  fullname .tl_set:N = \l_balaji_fullname_tl,
  key .tl_set:N = \l_balaji_key_tl,
  key .initial:n = {},
 }
\NewDocumentCommand\xauthor{ O{} m }
 {
  \group_begin:
  \keys_set:nn { balaji/author } { #1 }
  \keys_set:nn { balaji/author } { fullname = #2 }
  \balaji_define_author:n { #2 }
  \group_end:
 }

\cs_new_protected:Npn \balaji_define_author:n #1
 {
  \tl_if_empty:NT \l_balaji_lastname_tl
   {
    \seq_set_split:Nnn \l_balaji_author_seq { ~ } { #1 }
    \seq_pop_right:NN \l_balaji_author_seq \l_balaji_lastname_tl
    \seq_pop_left:NN \l_balaji_author_seq \l_balaji_firstname_tl
    \tl_set:Nx \l_balaji_initials_tl { \seq_use:Nn \l_balaji_author_seq { ~ } }
   }
  \tl_if_empty:NT \l_balaji_key_tl
   { \tl_set_eq:NN \l_balaji_key_tl \l_balaji_lastname_tl }
  \seq_gput_right:NV \g_balaji_author_list_seq \l_balaji_key_tl
  \prop_new:c { g_balaji_author_ \l_balaji_key_tl _prop }
  \balaji_populate:n { mail, web, address, firstname, initials, lastname, fullname }
 }

\cs_new_protected:Npn \balaji_populate:n #1
 {
  \clist_map_inline:nn { #1 }
   {
    \prop_gput:cnv { g_balaji_author_ \l_balaji_key_tl _prop } 
     { ##1 }
     { l_balaji_##1_tl }
   }
  %\prop_show:c { g_balaji_author_ \l_balaji_key_tl _prop } % for debugging
 }

\cs_generate_variant:Nn \prop_gput:Nnn { cnv }
\seq_new:N \l_balaji_author_seq
\seq_new:N \g_balaji_author_list_seq

\NewDocumentCommand{\getauthorfield} { m m }
 {
  \prop_item:cn { g_balaji_author_#1_prop } { #2 }
 }

\ExplSyntaxOff

\begin{document}

\xauthor{John X. Smith}

\xauthor[
  key=HK,
  web=http://x.y.z,
  firstname=Brian,
  lastname=Hamilton Kelly
]{Brian Hamilton Kelly}

\xauthor[
  key=VP,
  firstname=Charles,
  initials={L. X. J.},
  lastname={de la Vall\'ee Poussin},
]{Charles Louis Xavier Joseph de la Vall\'ee Poussin}

\getauthorfield{Smith}{firstname} \getauthorfield{Smith}{lastname}

\getauthorfield{HK}{web}

\end{document}

If the name is “complex”, you can and should add a key; the same if the same last name appears more than once. For a simple name, the key is set to the last name.

I set a global sequence containing the keys, so it can be mapped for retrieving the information. Of course much more should be done.

The information about the author whose key is KEY is contained in the property list \g_balaji_author_KEY_prop. Single fields can be retrieved by \getauthorfield{KEY}{<field name>}. It's easy to extend the set of fields.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .