1

I want to modify the citation macro of BibLaTeX so that:

  1. For the first citation, if the number of authors is less than 5, print out all of them regardless.
  2. In every other scenario, follow the normal APA citation style.

Here is what I have so far. It works partially by printing out all the authors at the first time, but the \ifthenelse seems always evaluate to true and execute the first branch (i.e., print out all the authors anyway)

\documentclass[stu, 12pt, biblatex]{apa7}
% APA citation style
\usepackage{csquotes}
\usepackage{hyperref}
\addbibresource{cite.bib}

\usepackage{xpatch}
\xpatchbibmacro{cite}{\printnames{labelname}}%
{%
    \ifciteseen{%
        \printnames{labelname}%
    }{%
        \ifthenelse{\value{listtotal} < 6}{%
            \printnames[][-\value{listtotal}]{labelname}%
        }{%
            \printnames{labelname}%
        }%
    }%
}
{}{}

\title{Test}
\author{Author}
\affiliation{Affiliation}
\course{Course}
\professor{Professor}
\duedate{\today}

\begin{document}

\maketitle

Researches had shown that \TeX\ is the best program \autocite{1Author}, \autocite{2Authors}, \autocite{3Authors}, \autocite{4Authors}, \autocite{5Authors}, \autocite{6Authors}

Researches had shown that \TeX\ is the best program again \autocite{1Author}, \autocite{2Authors}, \autocite{3Authors}, \autocite{4Authors}, \autocite{5Authors}, \autocite{6Authors}

\printbibliography

\end{document}

And here is the Bib file

@book{6Authors,
  title = {6 authors},
  author = {Cao, Mina and Anish, Pruitt and Lulu, Douglas and Zahra, Sing and Wesley, Smith and Anish, Pruitt},
}

@book{5Authors,
  title = {5 authors},
  author = {Mina, Goyal and Anish, Pruitt and Lulu, Douglas and Zahra, Sing and Wesley, Smith},
}

@book{4Authors,
  title = {4 authors},
  author = {Lulu, Douglas and Anish, Pruitt and Mina, Goyal and Zahra, Sing},
}

@book{3Authors,
  title = {3 authors},
  author = {Wesley, Smith and Anish, Pruitt and Mina, Goyal},
}

@book{2Authors,
  title = {2 authors},
  author = {Zahra, Sing and Mina, Cao},
}

@book{1Author,
  title = {1 author},
  author = {Anish, Pruitt},
}

1 Answer 1

0

The biblatex documentation says about listtotal (on page 189 in the description for \printnames, emphasis mine):

Whenever \printnames and \printlist process a list, information concerning the current state is accessible by way of four counters: the listtotal counter holds the total number of items in the current list, [...]. These counters are intended for use in list formatting directives. listtotal may also be used in the second optional argument to \printnames and \printlist. Note that these counters are local to list formatting directives and do not hold meaningful values when used anywhere else. For every list, there is also a counter by the same name which holds the total number of items in the corresponding list. For example, the author counter holds the total number of items in the author list. These counters are similar to listtotal except that they may also be used independently of list formatting directives.

Therefore in the \ifthenelse (which is not a list formatting directive) the listtotal counter does not have a meaningful value. Instead you have to use the labelname counter to get the number of entries in labelname:

\documentclass[stu, 12pt, biblatex]{apa7}
% APA citation style
\usepackage{csquotes}
\usepackage{hyperref}
\addbibresource{cite.bib}

\usepackage{xpatch}
\xpatchbibmacro{cite}{\printnames{labelname}}%
{%
    \ifciteseen{%
        \printnames{labelname}%
    }{%
        \ifthenelse{\value{labelname} < 6}{%
            \printnames[][-\value{listtotal}]{labelname}%
        }{%
            \printnames{labelname}%
        }%
    }%
}
{}{}

\title{Test}
\author{Author}
\affiliation{Affiliation}
\course{Course}
\professor{Professor}
\duedate{\today}

\begin{document}

\maketitle

Researches had shown that \TeX\ is the best program \autocite{1Author}, \autocite{2Authors}, \autocite{3Authors}, \autocite{4Authors}, \autocite{5Authors}, \autocite{6Authors}

Researches had shown that \TeX\ is the best program again \autocite{1Author}, \autocite{2Authors}, \autocite{3Authors}, \autocite{4Authors}, \autocite{5Authors}, \autocite{6Authors}

\printbibliography

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .