[Tex/LaTex] Getting ibid for apa-style citations from biblatex

apa-stylebiblatex

Goal: I want to cite using the biblatex-apa style, with the extension that (ibid.) is added, when the same source is quoted multiple times.


Note: This is a follow-up question to Getting ibid for numeric citations from biblatex

Also, I know that ibidem is explicitly not a part of the APA citation style and by some is even considered as old-fashioned or outdated, but every institution has their own requirements, and since biblatex-apa meets my requirements in every other aspect, I would like to add this little extension to it instead of using another style.

In the thread linked above, they do something similar with the numeric-comp-style, but copying the suggested code to my preamble does not help in my case. Since I am not experienced enough for this kind of "LaTeX Hacking", how would an equivalent code as the one suggested in the thread above look for biblatex-apa?

My minimal working document looks like this:

\documentclass[12pt,a4paper]{scrartcl}

% Bibliography entries:
\begin{filecontents}{literatur.bib}
@booklet{one,
author = {Author One},
title = {Testtitle 1.},
date = {2018},
}
@booklet{two,
author = {Author Two},
title = {Testtitle 2.},
date = {2018},
}
\end{filecontents}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} 
\usepackage{lmodern}
\usepackage[ngerman]{babel}   
\usepackage[backend=biber,style=apa,sortlocale=de_DE]{biblatex}
\DeclareLanguageMapping{ngerman}{ngerman-apa}
\addbibresource{literatur.bib}

\begin{document}
First citation should be normal \parencite{one}, second time with ibidem 
\parencite{one}, but after a second citation \parencite{two} it should 
appear as usual \parencite{one}.    
\printbibliography
\end{document}

This is what I get:

Document without ibidem

…and this is what i would like to get:

Document with ibidem

Note that (ebd.) ist just the german version of (ibid.).

Thank you a lot for any help and suggestions. 🙂

Best Answer

This needs a bit of code, but the actual changes to the original defintions from .cbx are not that big.

First we need to define a macro to print the ibidem, cite:ibid (copied from authoryear-ibid.cbx). We also request the ibidem tracker with ibidtracker=constrict and page tracking (to avoid a "ibid." at the beginning of a page) with pagetracker.

Then it is just a matter of inserting the conditional \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage} in the right place in the cite and textcite macros and adding a call to cite:ibid.

\documentclass[12pt,a4paper]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage[backend=biber, style=apa, pagetracker, ibidtracker=constrict]{biblatex}
\addbibresource{biblatex-examples.bib}

\makeatletter
\providecommand*{\mkibid}[1]{#1}

\newbibmacro*{cite:ibid}{%
  \printtext[bibhyperref]{\bibstring[\mkibid]{ibidem}}}

\renewbibmacro*{cite}{%
  \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
    {\usebibmacro{cite:ibid}}
    {\iffieldequals{fullhash}{\cbx@lasthash}
     % Multiple cites in one command
      {\setunit{\compcitedelim}%
       \usebibmacro{cite:plabelyear+extradate}}%
     % Single cite
      {\ifthenelse{\ifnameundef{labelname}\OR\iffieldequalstr{entrytype}{patent}}
     % No author/editor
         {\usebibmacro{cite:noname}%
          \setunit{\printdelim{nameyeardelim}}%
          \usebibmacro{cite:plabelyear+extradate}%
          \savefield{fullhash}{\cbx@lasthash}}
     % Normal cite
        {\ifnameundef{shortauthor}
           {\printnames[labelname][-\value{listtotal}]{labelname}}%
           {\cbx@apa@ifnamesaved
             {\printnames{shortauthor}}
             {\printnames[labelname][-\value{listtotal}]{author}%
              \addspace\printnames[sabrackets]{shortauthor}}}%
         \setunit{\printdelim{nameyeardelim}}%
         \usebibmacro{cite:plabelyear+extradate}%
         \savefield{fullhash}{\cbx@lasthash}}}}%
   \setunit{\multicitedelim}}

\renewbibmacro*{textcite}{%
  \iffieldequals{fullhash}{\cbx@lasthash}
   % Compact cite - more than one thing for same author
    {\setunit{\compcitedelim}%
     \usebibmacro{cite:plabelyear+extradate}}
   % New cite
    {%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
      \setunit{\compcitedelim}%
      \ifthenelse{\ifnameundef{labelname}\OR\iffieldequalstr{entrytype}{patent}}
    % No author/editor or patent
       {\iffieldundef{shorthand}%
    % Cite using title
         {\usebibmacro{cite:noname}%
          \setunit{\ifbool{cbx:np}%
                   {\printdelim{nameyeardelim}}%
                   {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
          \usebibmacro{cite:plabelyear+extradate}}
    % Cite using shorthand
         {\usebibmacro{cite:shorthand}}}
    % Normal cite with author/editor
    % Normal full cite
       {\ifnameundef{shortauthor}%
    % Normal full cite
         {\printnames[labelname][-\value{listtotal}]{labelname}}
    % Cite using short author
         {\cbx@apa@ifnamesaved
           {\printnames{shortauthor}}
           {\printnames[labelname][-\value{listtotal}]{author}}}%
    % Year
        \setunit{\ifbool{cbx:np}
                  {\printdelim{nameyeardelim}}
                  {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
    % Put the shortauthor inside the year brackets if necessary
        \ifnameundef{shortauthor}
         {}
         {\cbx@apa@ifnamesaved
           {}
           {\printnames{shortauthor}\setunit{\printdelim{nameyeardelim}}}}%
    % Actual year printing
        \ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
          {\usebibmacro{cite:ibid}}
          {\usebibmacro{cite:plabelyear+extradate}}%
    % Save name hash for checks later
        \savefield{fullhash}{\cbx@lasthash}}}}
\makeatother

\begin{document}
First citation should be normal \parencite{sigfridsson}, second time with ibidem
\parencite{sigfridsson}, but after a second citation \parencite{geer} it should
appear as usual \parencite{sigfridsson}.

\cite{nussbaum}

First citation should be normal \textcite{sigfridsson}, second time with ibidem
\textcite{sigfridsson}, but after a second citation \textcite{geer} it should
appear as usual \textcite{sigfridsson}.

\printbibliography
\end{document}

First citation should be normal (Sigfridsson & Ryde, 1998), second time with ibidem (ebd.), but after a second citation (Geer, 1985) it should appear as usual (Sigfridsson & Ryde, 1998). Nussbaum, 1978 First citation should be normal Sigfridsson und Ryde (1998), second time with ibidem Sigfridsson und Ryde (ebd.), but after a second citation Geer (1985) it should appear as usual Sigfridsson und Ryde (1998).