1

I am trying to display the initials of only the first name of my authors in my citations. So, I should get the following format: (J. Kennedy et al., 2023) and not (John Fitzgerald Kennedy et al., 2023).

There is a solution for this in LaTeX using Biblatex. However, the code (from here) used to solve this is old and does not use the Biblatex 3.3 naming convention.

When I run the below MWE, I get the following error:

Illegal parameter number in definition of \blx@defformat@d.

<to be read again> 4 l.23 \usebibmacro{name:first-last}{#1}{#4 }{#5}{#7}%

Here is how much of LuaTeX's memory you used: 6844 strings out of 481315 125171,662416 words of node,token memory allocated 430 words of node memory still in use: 2 hlist, 1 rule, 1 dir, 3 kern, 1 glyph, 3 attribute, 59 glue_spec, 3 attribute_list, 1 write nodes avail lists: 2:18,3:3,4:3,5:1,7:2,9:3 23963 multiletter control sequences out of 65536+600000 25 fonts using 3258707 bytes 36i,0n,33p,816b,67s stack positions out of 5000i,500n,10000p,200000b,100000s ! ==> Fatal error occurred, no output PDF file produced!

The legacy solution for this is:

\documentclass[]{article}

\usepackage{filecontents} \begin{filecontents}{bib.bib} @article{jdoe, author = {John Paul Peter Julian Doe}, journal = {Journal}, title = {Title}, year = 2014, pages = 111--222, } \end{filecontents}

\usepackage[style=authoryear]{biblatex} \addbibresource{bib.bib}

% Helper function to get initial letter \def\firstinit#1{\justfirst#1\relax} \def\justfirst#1#2\relax{#1}

% Format for FirstInitials - LastName (standard implementation) \DeclareNameFormat{firstinits-last}{% \usebibmacro{name:first-last}{#1}{#4}{#5}{#7}% \usebibmacro{name:andothers}}

% Format for VeryFirstInitial - LastName \DeclareNameFormat{firstfirstinit-last}{% \usebibmacro{name:first-last}{#1}{\firstinit{#4}\adddot}{#5}{#7}% \usebibmacro{name:andothers}}

% Set format for sortname (bibliography) and labelname (citation) \DeclareNameAlias{sortname}{firstinits-last} \DeclareNameAlias{labelname}{firstfirstinit-last}

\begin{document}

\noindent Citation: \cite{jdoe}.

\printbibliography[]

\end{document}

Can anyone help me adapt this legacy code using the new Biblatex 3.3 naming convention?

Henri Menke
  • 109,596

1 Answers1

3

Nowadays, I would make use of biblatex's extended name format (see for example Use only the last name as namepartfamily instead of everything after prefix, How to enter an author name that has a surname and a Junior component but no first name?, Bibtex/Biber: how to cite an author using Ethiopian conventions?) and give the initials explicitly

\documentclass{article}

\usepackage[style=authoryear, giveninits=true,]{biblatex}

\DeclareNameAlias{labelname}{given-family}

\begin{filecontents}{\jobname.bib} @article{jdoe, author = {family=Doe, given={John Paul Peter Julian}, given-i={J}}, journal = {Journal}, title = {Title}, year = 2014, pages = {111--222}, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} \noindent Citation: \cite{jdoe}.

\printbibliography \end{document}

Citation: J. Doe 2014.//Doe, J. (2014). “Title”. In: Journal, pp. 111–222.


If you want to stick to the macro solution (which can break down badly for non-ASCII chars and other input), try

\documentclass{article}

\usepackage[style=authoryear]{biblatex}

\def\firstinit#1{\justfirst#1\relax} \def\justfirst#1#2\relax{#1}

\renewcommand*{\mkbibnamegiven}[1]{% \expandafter\firstinit\expandafter{#1}\bibinitperiod}

\DeclareNameAlias{labelname}{given-family}

\begin{filecontents}{\jobname.bib} @article{jdoe, author = {John Paul Peter Julian Doe}, journal = {Journal}, title = {Title}, year = 2014, pages = {111--222}, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} \noindent Citation: \cite{jdoe}.

\printbibliography \end{document}

for the same result in the MWE.

moewe
  • 175,683
  • This is an interesting solution. Thank you for taking the time-out for giving it. Just a quick question, wow can I declare what the given-i is for each author? I have a love long bib file and cannot do this manually. Any suggestion on how best to do this? – Mohamed Yusuf Feb 28 '23 at 05:16
  • @MohamedYusuf If you want to "normalise" a name, you can try the sourcemap shown on p. 208 of the biblatex documentation. – moewe Feb 28 '23 at 06:22
  • This is great. Thank you. In your second solution, how can only use the initials when there is more than one author with the same surname?? Right now, all authors have their initials in the citations. Thank you! – Mohamed Yusuf Feb 28 '23 at 10:00
  • @MohamedYusuf Remove the \DeclareNameAlias{labelname}{given-family}. You may or may not get better results if you additionally pass giveninits=true, to biblatex as loading option. – moewe Feb 28 '23 at 10:52
  • This works. One last question. How do I keep all first initials in the bibliography, but selecting only the first initial in the citation? – Mohamed Yusuf Feb 28 '23 at 11:10
  • 1
    @MohamedYusuf https://gist.github.com/moewew/04ec6a78d352bd19f63a2323236d0a76, but this could go wrong if you have "J. E. Doe" and "J. F. Doe". biblatex thinks these are two different names and treats them as such, but your citations will both shows "J. Doe" creating the wrong impression that they are the same. – moewe Feb 28 '23 at 12:09
  • Worked like a charm. Youre a life saver. Thank you! – Mohamed Yusuf Feb 28 '23 at 13:34