0

I am writing a new class for a journal.

To introduce the authors and affiliations information, an author has just to insert this in his/her article

\author[1]{Name1 Surname1}
\author[2]{Name2 Surname2}
\author[2]{Name3 Surname3}
\author[3]{Name4 Surname4}
\author[4]{Name5 Surname5}

\affiliation[1]{Affiliation1} \affiliation[2]{Affiliation2} \affiliation[3]{Affiliation3} \affiliation[4]{Affiliation4}

Where the numbers are needed to match each author with its own affiliation.

The class is almost ready now, and everything works correctly.

Based on these and other fields that authors fills in their tex file, in the frontmatter of the article there will be a sentence like this:

Citation: Name1 Surname1, Name2 Surname2, Name3 Surname3..., Title, Journal Name, vol. .....

Today I have been asked for a "small" change, that is to modify the sentence like this;

Citation: N1. Surname1, N2. Surname2, N3. Surname3..., Title, Journal Name, vol. .....

That is, to have only the initials typesetted for the given names, whereas in the author line that full names should be maintained.

Now, bibtex and biblatex calculate automatically the initials from the bib files. however, this text should be put in the frontmatter of the final pdf "on the fly", from information contained in the tex file, and without any intervention of bibtex/biblatex.

Hence the question is: given the argument of the \author[]{} command, which contains the name and surname of that specific author, is it possible to extract the initials of the given name? And, obviously, to be robust to double/more given names?

Actually, replicate what bibtex does, but directly in my latex class?

PS: the other option is to provide authors with a second command, let's say, \authorInitials{} and ask the authors to fill it.

Thanks

Federico Is there a way to extract the initials of given names from the autho

TrAmA
  • 15

1 Answers1

1

Take a look at this answer. Adapted MWE:

\documentclass[]{article}

\def\justfirst#1#2 #3\relax{#1.\if\relax#3\else{}~\justfirst#3\relax\fi} \def\firstinit#1{\justfirst#1 \relax\relax}

\newcommand{\abbrevname}[2]{\firstinit{#1}~{#2}}

\begin{document} My hero is \abbrevname{John Paul}{Jones}. \end{document}

Of course you should store author names and supply the first and last names separately to \abbrevname. You could, in principle, count words and abbreviate everything except the last word, but that would need additional check for particles (de, de la, von etc.), hyphenation and numerous other cases. So it might be a good idea to get the first and last names separately in the \author macro to avoid ambiguity with names of more than two words.

The nameauth package might be useful to define your \author macro and store names. It can handle a variety of cases (see this answer for a detailed list).