# Getting ibid for apa-style citations from biblatex

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}

\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:

...and this is what i would like to get:

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

Thank you a lot for any help and suggestions. :)

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}

\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}%
% Single cite
{\ifthenelse{\ifnameundef{labelname}\OR\iffieldequalstr{entrytype}{patent}}
% No author/editor
{\usebibmacro{cite:noname}%
\setunit{\printdelim{nameyeardelim}}%
\savefield{fullhash}{\cbx@lasthash}}
% Normal cite
{\ifnameundef{shortauthor}
{\printnames[labelname][-\value{listtotal}]{labelname}}%
{\cbx@apa@ifnamesaved
{\printnames{shortauthor}}
{\printnames[labelname][-\value{listtotal}]{author}%
\setunit{\printdelim{nameyeardelim}}%
\savefield{fullhash}{\cbx@lasthash}}}}%
\setunit{\multicitedelim}}

\renewbibmacro*{textcite}{%
\iffieldequals{fullhash}{\cbx@lasthash}
% Compact cite - more than one thing for same author
{\setunit{\compcitedelim}%
% 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}}%
% 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}}
% 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}}
% 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}


• Very nice - thank you for the great explanation and answer! :) Sep 4 '18 at 12:29
• @Pidrittel If the chapter starts on a new page the page tracking already takes care of that. You can use the command \citereset to reset ibidem tracking (and a bit more if applicable) at a certain point. With the citereset option (p. 52 of the documentation) you can automatically execute that command at the beginning of a \chapter or \section. The biblatex-apa feature to show the full list of authors at a first citation can be reset with \citeresetapa, but there is no option to have this applied automatically at each section. Sep 4 '18 at 12:40
• @Pidrittel The code I posted should not influence whether or not "ibid" tracking is turned on or off in floats. (i) Can you reproduce a similar problem when you just use the standard style style=authoryear-ibid instead of the complicated code? (ii) Please ask a new question with a short example document (MWE/MWEB) that shows the issue, include a screenshot of the output you get and explain what you would like to see instead. If you can reproduce the issue with style=authoryear-icomp use that. Sep 12 '18 at 14:49
• @Pidrittel Good. I remember that when you first commented a few days ago I threw together a very small MWE and there the tracking was disabled in floats, so I'm not just asking to annoy you, this really should not happen and an MWE is the only way to find out if there is a bug and how to fix it. Sep 12 '18 at 14:56
• @Pidrittel Ah yes, just today I learned that H makes float environments behave very weirdly. If you need a deeper investigation into this issue, please open a new question. Sep 22 '18 at 20:58