# First author in bibliography in lastname, firstname but subsequent authors as firstname lastname

The Australian Legal Citation Guide v3 states that for a bibliography, the entry for a book should have the first author appear as lastname, firstname and then all subsequent authors appear as firstname lastname, e.g.

Cook, Catriona, Robin Creyke and Robert Geddes

The macro below does this by printing out the first author entry in last, first order and then adding a comma and a space if there is no 'et al' following. I find this doesn't work though. I'm trying to use the \ifandothers test but it seems always to return false. So for an 'et al' entry I end up with:

Cook, Catriona, et al

I am trying to do this with the macro below. I've been at it for hours and I'm brand new to LaTeX and biblatex so I'm pulling what hair I have left out in frustration.

Is the macro I am using correct? I suspect this is a noob error. I would appreciate any help.

PS: I'm not even up to the editor part of the macro yet.

PPS: This code comes from aglc2.cbx which is part of Will Hardy's AGLC style and is posted at http://github.com/willhardy/aglc

\newbibmacro{author/editor:lastnamefirst}{%
\ifthenelse{\ifuseauthor\AND\NOT\ifnameundef{author}}%
{\ifuseauthor{%
\ifandothers{author}{%
\printnames[sortname][1-1]{author}%
\printnames[default][2-2]{author}%
} {%
\printnames[sortname][1-1]{author}%
\printnames[default][2-3]{author}%
}%
}{}}%
{\ifthenelse{\ifuseeditor\AND\NOT\ifnameundef{editor}}{\printnames[sortname]{editor}}{}}%
}


UPDATE: In response to @lockstep's suggestion here is some code that shows that I could not get \DeclareNameAlias to work:

\documentclass[titlepage]{article}
\usepackage[style=aglc2,backend=biber]{biblatex}
\DeclareNameAlias{default}{last-first/first-last}
\bibliography{week1}

\begin{document}
Test citations here:\footcite{ldtl7} and here:\footcite{ldtl7a}
\printbibliography
\end{document}


Here's the bib file:

@BOOK{ldtl7,
year       = 2009,
author     = {Catriona Cook and Robin Creyke and Robert Geddes and David Hamer},
title      = {Laying Down the Law},
edition    = 7,
publisher  = {LexisNexis Butterworths}
}
@BOOK{ldtl7a,
year       = 2009,
author     = {Catriona Cook and Robin Creyke and Robert Geddes},
title      = {Laying Down the Law2},
edition    = 7,
publisher  = {LexisNexis Butterworths}
}


Here's the output:

References
Cook, Catriona, Robin Creyke and Robert Geddes, Laying Down the Law2 (LexisNexis Butterworths, 7th ed, 2009)
Cook, Catriona, Robin Creyke et al, Robert Geddes, Laying Down the Law (LexisNexis Butterworths, 7th ed, 2009)


And in the footnotes:

1 Cook, Catriona, Robin Creyke et al, Robert Geddes, Laying Down the Law (LexisNexis Butterworths, 7th ed, 2009).
2 Cook, Catriona, Robin Creyke and Robert Geddes, Laying Down the Law2 (LexisNexis Butterworths, 7th ed, 2009).

-
Seamus, I haven't done this because I want 'et al' to be printed if there's more than 3 authors. But at the moment I get "Lastname, Firstname, et al" instead of "Lastname, Firstname et al" (extra comma and space inserted) –  Mark Ferraretto Feb 16 '11 at 14:38
You should become a member of the panel that decides on the Australian Legal Citation Guide and make them abolish this guideline. –  Hendrik Vogt Feb 16 '11 at 14:50
@Mark: It is unusual around here to sign your questions (as there is already a box with your name below it) or to have any greeting. –  Hendrik Vogt Feb 16 '11 at 14:52
@Mark: maxnames=3 (or \printbibliography[maxnames=3]) should do the trick, indeed (though this option is not called “maxauthors”). There should be no comma before the “et al.” Please create a minimal example if the behaviour is different for you. –  domwass Feb 16 '11 at 15:11
@Mark: I think the problem is that you've done some rather 'hacky' things with the author-formatting code in aglc2. I'd suggest you might want to take a bit of a step back, and work through your .bbx and .cbx files from scratch. Build up slowly, starting by loading some standard biblatex ones, and test at each stage. –  Joseph Wright Feb 19 '11 at 6:26

It shouldn't be necessary to define new macros. Try the following:

\documentclass{article}

\usepackage[style=verbose]{biblatex}

\AtBeginBibliography{%
\DeclareNameAlias{default}{last-first/first-last}%
}
\renewcommand*{\finalnamedelim}{%
%   \ifnumgreater{\value{liststop}}{2}{\finalandcomma}{}% DELETED

\usepackage{filecontents}

\begin{filecontents}{biblatextest.bib}
@book{CCG01,
author = {Cook, Catriona and Creyke, Robin and Geddes, Robert},
year = {2001},
title = {Alpha},
}
\end{filecontents}

\begin{document}

Some text \autocite{CCG01}.

\printbibliography

\end{document}


EDIT: Example updated to use \AtBeginBibliography.

(The filecontents environment is only used to include some external files directly into the example, so that it compiles. It is not necessary for the solution.)

-
@lockstep: @Mark complained about the comma before “et al.” which should not be there with standard biblatex settings. But if he meant the comma before the “and”, then you’re right. –  domwass Feb 16 '11 at 15:14
@lockstep: I just ran your file and it works. I added an extra author and it formats this correctly too. But I have no idea how it works! Could you explain it? –  Mark Ferraretto Feb 16 '11 at 15:25
@Mark: I didn't use the AGLC styles but simply hoped they would work similar to the built-in styles. \DeclareNameAlias is responsible for switching first and last names, while \finalnamedelim is the macro responsible for typesetting a comma plus "and" before the last author (or, as redefined, typesetting only "and"). –  lockstep Feb 16 '11 at 15:31
@lockstep: while your sample works (marvellously) I can't seem to transplant it into the AGLC style. I added the \DeclareNameAlias and \finalnamedelim to aglc2.cbx and after to aglc2.bbx. I then reverted to using the standard author/editor macro for printing my book entries. The spacing is good and the comma has gone but now the authors' names appear as firstname lastname instead of lastname firstname eg: "Catriona Cook, Robin Creyke..." instead of "Cook, Catriona, Robin Crekye...". –  Mark Ferraretto Feb 16 '11 at 23:36
@lockstep: I hope you don't mind but I've made the versions of aglc2.?bx available for you to check out. Here are aglc2.cbx and aglc2.bbx. I would appreciate you taking a look. I hope that's OK. –  Mark Ferraretto Feb 16 '11 at 23:36

I think I have it although I'm not entirely sure why. It seems there were two issues to solve. The first one was what I asked ie: how to have only the first author appear as last-first with subsequent authors appear first-last. To fix this I altered the sortname DeclareNameFormat in aglc2.cbx. It now looks like this:

\DeclareNameFormat{sortname}{%
\ifthenelse{\value{listcount}=1}
{
\usebibmacro{name:last-first}{#1}{#3}{#5}{#7}%
\usebibmacro{name:andothers}
}
{
\ifthenelse{\value{listcount}>1\and\value{listtotal}>\value{liststop}}
{}
{%
\usebibmacro{name:first-last}{#1}{#3}{#5}{#7}%
}%
}
}


I'm pretty confident this is a decent solution.

The strange bit is how I fixed the 'et al' placement. I know what I did but I don't know why it works. I had to make two changes. The first was to delete this macro:

\renewbibmacro*{name:andothers}{%
\ifthenelse{\value{listtotal}>\value{liststop}\AND\value{listcount}=2\AND\ifmorenames}%
{}}


The existence of this macro seemed to be the cause of not having 'et al' printed at all.

The second change was to change this:

\renewbibmacro*{author}{%
\ifuseauthor
{\printnames[][1-3]{author}}
{}}


to this

\renewbibmacro*{author}{%
\ifuseauthor
{\printnames{author}}
{}}


This seemed to be the cause of having 'et al' appear after the second author instead of after the first. Why is beyond me. But now that these changes are made, the style seems to be working properly.

So I think I'm there! I'd love to find out more about those last two changes so they don't bite me later but at least I'm where I want to be... for now.

Thanks to everyone who helped. Having the discussion with you all is what made this possible. I appreciate your guidance.

-