# Get surnames from \author command

I want to put the author surnames in the running header. This is what I currently do:

\documentclass{article}
\author{Foo Bar, Baz Bah}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\begin{document}
\thispagestyle{empty}
\maketitle
\clearpage

\chapter{Introduction}
\clearpage

\chapter{Conclusion}
\end{document}


However, according to DRY principle, I want to avoid defining the names in multiple places. Instead I would like to extract this information from having used the \author command previously. Is this possible?

• The main problem is trying to figure out which word is the surname. An English name like John Lee, the surname is the 2nd name. The Chinese put the surnames in front so names like Lee Kwan Yew the surname is Lee. Sometimes, if they have a Christian name they might write it like John Lee Kok Pin where the surname Lee is the second word. The other one you need to cater for is South Indian or Singhalese one word names like Tharumalingamsivaloganathan.
– cup
Sep 16 at 18:34

Probably the manual approach is much easier. bib{tex,latex} has a lot of code for that, and it's always based on the fact that in the database you manually divide them.

For example (fake names), I am John Francis Smith --- and my surname is "Smith". But my collegue next door is Pablo Rojas Verde, and his surname is "Rojas Verdes". See https://shinesolutions.com/2018/01/08/falsehoods-programmers-believe-about-names-with-examples/ for even nicer examples (notice especially the point #30).

I would go for the reverse approach (a lot of journals do this):

% keep together in the source
\newcommand{\fullnames}{John Francis Smith, Pablo Rojas Verde}
\newcommand{\runningnames}{Smith, Rojas Verdes}
...
\authors{\fullnames}
...


...and use the macros whenever you can need them. You have just one point where you do the changes, but the separation on what is name and what surnames must be done, basically, by hand.

• Good frame challenge, +1. I will wait with accepting this answer to see if somebody has a useful answer for the original question. Sep 16 at 11:43

The utility of an automated solution will depend on the volume of information to be managed.

But, as mentioned in the other answer, labelling the data still has to be done by the human/AI. (E.g., when a mixture of familyname-first versus givenname-first typesetting. E.g., multi-word names. E.g., ranks, titles, positions, descriptors: Dumas fils, Thurston-Howell III, Doctor Zhivago.)

Given some rules, string-parsing or regex could be solutions. (Note that, the \author command should expand to a mixture of further commands and material to be typeset, so expl3's regex would be best: it can tell the two apart.)

Here, to illustrate the level of complexity required (even for just one name), I show two methods of structured information storage-and-retrieval: atomistically manual, and automated; with the latter using existing bibliographical machinery.

(I) Manual

Use macros, and build up compound components from simpler components. Basically, name all the data elements, then assemble them.

MWE

\documentclass{book}

\newcommand\authorgivennamea{Foo}
\newcommand\authorfamilynamea{BarFamily}
\newcommand\authorgivennameb{Bar}
\newcommand\authorfamilynameb{BahFamily}
\newcommand\aspace{\ }
\newcommand\acomma{,}
\newcommand\authornamedelimiter{\aspace}
\newcommand\authornamesdelimiter{\acomma\aspace}
\newcommand\authora{\authorfamilynamea\authornamedelimiter\authorgivennamea}
\newcommand\authorb{\authorfamilynameb\authornamedelimiter\authorgivennameb}

\title{Some Title}
\author{\authora\authornamesdelimiter\authorb}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\begin{document}
\thispagestyle{empty}
\maketitle
\clearpage

\chapter{Introduction}
\clearpage

\chapter{Conclusion}
\end{document}


II Bibliographical

Structured information implies a database; bibliographic information is database-ical; so, let's use biblatex and a .bib file.

With a bib entry like:

@book{currentauthors,
author={Foo Barfamily and Bar Bahfamily},
}


and using the authoryear style

\usepackage[style=authoryear]{biblatex}


and using the \citeauthor citation command for the header

\lhead{\citeauthor{currentauthors}}


we get this

straight out of the box because biblatex/biber already knows about author name lists and how to parse and process them.

Citation commands can be customised, if desired (e.g., to output ,  as delimiter instead of and (for two names)),

MWE

\begin{filecontents*}[overwrite]{\jobname.bib}
@book{currentauthors,
author={Foo Barfamily and Bar Bahfamily},
}
\end{filecontents*}

\documentclass{book}
\usepackage[style=authoryear]{biblatex}
\title{Some Title}
\author{\citeauthor{currentauthors}}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\begin{document}
\thispagestyle{empty}
\maketitle
\clearpage

\chapter{Introduction}
\clearpage

\chapter{Conclusion}
\end{document}


The question resolves into an optimization exercise, ultimately.