TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


  \seq_set_split:Nnn \l_tmpa_seq { ~ } { #1 }
  \seq_pop_left:NN \l_tmpa_seq #1

  \seq_set_split:Nnn \l_tmpa_seq { ~ } { #2 }
  \seq_pop_right:NN \l_tmpa_seq #1

\author[mail=john@gmail.com, web="http://www.tex.stackexchange.com", address=Department of Mathematics, UK]{John Smith} %% mail value should store \mail{john@gmail.com}, 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{Brian H.-K. Lly}

share|improve this question
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 '13 at 10:29
@egreg I have updated the questions and \author{Brian H.-K. Lly} it's possible to automate? – Balaji Sep 4 '13 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 '13 at 11:32
up vote 4 down vote accepted

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

\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 }
  \keys_set:nn { balaji/author } { #1 }
  \keys_set:nn { balaji/author } { fullname = #2 }
  \balaji_define_author:n { #2 }

\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_get:cn { g_balaji_author_#1_prop } { #2 }



\xauthor{John X. Smith}

  lastname=Hamilton Kelly
]{Brian Hamilton Kelly}

  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}



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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.