GeneralAdd "and" before last Author in Citations

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
arstaer
Posts: 12
Joined: Sun Jun 17, 2012 5:56 am

Add "and" before last Author in Citations

Post by arstaer »

Dear all,

I am trying to insert "and" before the last author in citations using biblatex-chicago (0.9.9c).

MWE:

Code: Select all

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[
  backend=biber,
  authordate,
  doi=false,
  url=false,
  isbn=false,
  bibencoding=UTF8,
  texencoding=auto,
  maxnames=2,
  maxbibnames=99,
  minnames=1
]{biblatex-chicago}
\addbibresource{biblatex-examples.bib}

% To have commas in multiple citation instead of semicolons
\renewcommand\multicitedelim{\addcomma\space}
\renewcommand*{\newunitpunct}{\addcomma\space}

\begin{document}
\textcite{knuth:ct:a}. And one more, \textcite{knuth:ct:a, knuth:ct:a}.
\textcite{knuth:ct:a, markey, knuth:ct:a}
\printbibliography
\end{document} 
How can I make the last citation into "Knuth (1984), Markey (2005) and Knuth (1984)"?

I tried several approaches form TeX.sx. For example, this piece of code which works great but disables all other modifications to \textcite. For instance, repeated citation now show only a year instead of full repeated citation and same authors but different years show up as author (year), year.

Code: Select all

\newcounter{cbx:totalcite}
\newbibmacro{textcite:count}{%
  \iffirstcite
    {\setcounter{cbx:totalcite}{1}}
    {\addtocounter{cbx:totalcite}{1}}}

\newbibmacro{textcite:delim}{%
  \iffirstcite
    {}
    {\iflastcite
       {\ifnumgreater{\value{cbx:totalcite}}{2}
          {\finalandcomma\space\bibstring{and}\space}
          {\addspace\bibstring{and}\space}}
       {\addcomma\space}}}

\def\iffirstcite{%
  \ifboolexpr{ ( test {\ifnumequal{\value{multicitetotal}}{0}}
                 and test {\ifnumequal{\value{citecount}}{1}} )
               or ( test {\ifnumgreater{\value{multicitetotal}}{0}}
                    and test {\ifnumequal{\value{multicitecount}}{1}}
                    and test {\ifnumequal{\value{citecount}}{1}} ) }}

\def\iflastcite{%
  \ifboolexpr{ test {\ifnumequal{\value{citecount}}{\value{citetotal}}}
               and test {\ifnumequal{\value{multicitecount}}{\value{multicitetotal}}} }}

\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}% <precode>
  {\usebibmacro{citeindex}% <loopcode>
   \usebibmacro{textcite:count}%
   \usebibmacro{textcite:delim}%
   \usebibmacro{textcite}}
  {\ifbool{cbx:parens}
     {\bibcloseparen\global\boolfalse{cbx:parens}}
     {}}% <sepcode>
  {\usebibmacro{textcite:postnote}}% <postcode>

\DeclareMultiCiteCommand{\textcites}{\textcite}{}
There is also another code that it tried.

Code: Select all

\makeatletter
\newbibmacro*{textcite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
    {\multicitedelim}
    {\cbx@tempa
     \ifnameundef{labelname}
       {\printfield[citetitle]{labeltitle}}
       {\printnames{labelname}}%
     \addspace\bibopenbracket}%
  \ifnumequal{\value{citecount}}{1}
    {\usebibmacro{prenote}}
    {}%
  \usebibmacro{cite}%
  \savefield{namehash}{\cbx@lasthash}%
  \ifnumequal{\value{citecount}}{\value{citetotal}-1}
    {\gdef\cbx@tempa{\bibclosebracket\addspace\bibstring{and}\addspace}}%
    {\gdef\cbx@tempa{\bibclosebracket\multicitedelim}}%
}  
\makeatother
But this doesn't compile throwing up an error,

Code: Select all

! Undefined control sequence.
<argument> \cbx@tempa 
                      \ifnameundef {labelname} {\printfield [citetitle]{labe...
Is there any other way to make this work? Would greatly appreciate any help.

Thank you,

Arsenio

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply