# Check if an entry is cited multiple times

I am trying to find out whether it is currently possible to have a test in Biblatex that tests at the very first time an entry is cited whether the same entry will be cited more than once in the current reference section (i.e. the entire paper, or the chapter in case of a book).

The real world usage scenario is legal citations, namely the Canadian Guide to Uniform Legal Citation, which, while slightly ambiguous, states that "it is not necessary to establish a short form for cases if they are not referred to in any subsequent paragraph" (in practice, most papers I see will only give the short form if the case is cited subsequently, which makes sense as otherwise, given the abundance of cases cited just once in a usual paper, any way to make the footnote shorter is welcome).

So let's say I cite Elders Pastoral Ltd v Bank of New Zealand. The first footnote would then say "Elders Pastoral Ltd v Bank of New Zealand [1989] 2 N.Z.L.R. 180 (C.A.) [Elders]", all subsequent footnotes would say "Elders, supra n. 1". However, I need the printing of the shorthand field to be conditional on the entry to be cited more than once.

I have a vague idea that might be possible by doing something along the following lines.

Here is my current macro to make a footnote for a case:

\newbibmacro*{footcite:jurisdiction}{%
\global\boolfalse{cbx:loccit}%
\ifciteseen
{\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}
{\usebibmacro{footcite:ibid}}
{\usebibmacro{footcite:jurisdiction:note}}}
{\usebibmacro{footcite:full:jurisdiction}%


And here is the footcite:full:jurisdiction macro

\newbibmacro*{footcite:full:jurisdiction}{%
\printtext{%
\bibhypertarget{\thefield{entrykey}:\the\value{instcount}}{%
\usedriver
{\DeclareNameAlias{sortname}{default}}
{jurisdiction}}}%
\usebibmacro{shorthandintro:jurisdiction}}
\usebibmacro{footcite:save}}}


So in the footcite:full:jurisdiction, I would make the \usebibmacro{shorthandintro:jurisdiction} dependent on the test for a variable and in the footcite:jurisdiction, I would set the variable in case the \ifciteseen yields true. This would then work after two LaTeX runs.

However, my question would be what type of variable to use and how to to set it, so as to avoid errors (for instance, I think using a boolean and do an \ifbooltrue test would result in errors like "boolean variable cbx:???? not set" errors on the first run).

Any ideas are very welcome.

• Welcome to tex.sx! Note that it is unusual around here to sign your questions (as there is already a box with your username below it) or to have any greeting. Mar 4, 2011 at 20:19
• Regarding legal citation, this might interest you: Coordinating the work of Biblatex style authors May 10, 2012 at 16:41

As per @Seamus suggestion, I edited my original answer, rather than add a new one; my initial answer was not entirely correct, and in case anyone ever has the same problem, my experience might be helpful. While my initial solution would work, it would also give me errors I did not notice initially because TextMate seemed to suppress them. Only when I compiled in the terminal would I see them. So here is how I changed and simplified it.

First, I begin with the footcite:jurisdiction macro:

\newbibmacro*{footcite:jurisdiction}{%
\global\boolfalse{cbx:loccit}%
\ifciteseen%
{\ifthenelse{\ifciteibid\AND\NOT\iffirstonpage}%
{\usebibmacro{footcite:ibid}}%
{\usebibmacro{footcite:jurisdiction:note}}}%
{\usebibmacro{footcite:full:jurisdiction}%
\usebibmacro{footcite:save}}}


Nothing spectacular here, it is just a variation of the regular footcite macro. Notice that it calls the footcite:jurisdiction:note macro when the case is cited at least once not for the first time and not with ibid (which is exactly the scenario in which I want the shorthand to be printed in the first citation). The footcite:jurisdiction:note macro goes like this:

\newbibmacro*{footcite:jurisdiction:note}{%
\usebibmacro{jurisdiction:multipletimes}%
\ifbool{bbx:jurisdiction:germany}%
{\usebibmacro{court+location:germany}% Case id for German cases
\iffieldundef{origtitle}%
{\printfield{title}}%
{\printfield{origtitle}}}
{\iffieldundef{shorthand}% Case id for English-style cases
{\usebibmacro{casename}}
{\printfield{shorthand}}}%
\usebibmacro{seenote}%
\iffieldundef{postnote}%
{}%
}


The jurisdiction:multipletimes macro sets the variable which will be checked to determine whether the shorthand needs to be printed. Because the macro is only called at the second citation at the earliest, but the shorthand needs to be printed at the first citation, it writes to the aux file. The macro goes like this:

\newbibmacro{jurisdiction:multipletimes}{%
\iffieldundef{shorthand}%
{}%
{\if@filesw
\protected@write\@mainaux{}%
{\string\csxdef{cbx@\thefield{entrykey}:short:%
\csuse{cbx@first@\thefield{entrykey}}}{multi}}%
\fi
}%
}%


To my understanding, the \if@fileswchecks whether the aux file is writeable which seemed like a good idea to check for. The \protected@write\@mainaux{} writes to the main aux file. The \string writes the following command verbatim instead of expanding it before being written to the aux file. The \csxdef sets the variable that is later used to check whether the entry has been cited multiple times. The next cbx@\thefield{entrykey} is not preceded by a \string because we want itto expand before being written to the aux file to make a unique variable name for each entry. The name of the variable also contains the \csuse{cbx@first@\thefield{entrykey}} part because that part, which expands since it is not preceded by \string, will be unique for a citation within a reference section, such as a chapter. This way, the test will be performed on a per-reference section basis rather than globally.

The footcite:full:jurisdiction no longer contains any reference to the variable used for the test. It goes like this:

\newbibmacro*{footcite:full:jurisdiction}{%
\printtext{%
\bibhypertarget{\thefield{entrykey}:\the\value{instcount}}{%
\usedriver%
{\DeclareNameAlias{sortname}{default}}%
{jurisdiction}}}%
\iffieldundef{postnote}%
{}%


The jurisdiction:shortform:intro is, unlike in my original question, now called by the driver for jurisdiction, and thus implicitly by footcite:full:jurisdiction. It goes like this:

\newbibmacro{jurisdiction:shortform:intro}{%
\ifcsstring{cbx@\thefield{entrykey}:short:%
\the\value{instcount}}{multi}%
{\printfield{shorthand}%
\ifcsstring{cbx@\thefield{entrykey}:orig}{orig}%
{}}%
}%
{\ifcsstring{cbx@\thefield{entrykey}:orig}{orig}%
{}%
}%
}%


As long as we are in the same reference section, cbx@\thefield{entrykey}:short:\the\value{instcount} will be the same as cbx@\thefield{entrykey}:short:\csuse{cbx@first@\thefield{entrykey}}, because the general footcite:save macro sets cbx@first@\thefield{entrykey} to \the\value{instcount} at the first full citation within the current reference section.

Notice here that it also contains a test whether the original title needs to be printed, which was not part of my initial question, but the mechanism for doing that is similar. (For anyone interested, the original title test tests whether any citation of the case contains a pinpoint, in which case the reporter cited to, provided by the origtitle field, is given in the first citation of the case).

• It's great that you posted a solution to your problem. If no better solutions are coming, you can also accept the answer to your own question by clicking the checkmark. Mar 11, 2011 at 7:12
• To give credit where credit is due, the new answer and the usage of csxdef is inspired by the answer to this question. Mar 13, 2011 at 12:14

This has become very easy to do with biblatex v1.3: This version introduced the citecounter counter which "indicates how many times the entry currently being processed is cited in the current reference section" (manual, section 4.6.2). In the following MWE, I use the \ifnumgreater test from the etoolbox package which is loaded by biblatex.

EDIT: It should be noted that the citecounter feature was introduced because of a feature request of the OP jjbornheim at SourceForge.net: biblatex.

\documentclass{article}

\usepackage[style=verbose,citecounter=true]{biblatex}

\renewbibmacro*{cite:full}{%
\usebibmacro{cite:full:citepages}%
\printtext[bibhypertarget]{%
\usedriver
{\DeclareNameAlias{sortname}{default}}
{\thefield{entrytype}}}%
%   \usebibmacro{shorthandintro}}% DELETED
\ifnumgreater{\value{citecounter}}{1}{% NEW
\usebibmacro{shorthandintro}% NEW
}{% NEW
}% NEW
}% NEW

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
shorthand = {AL},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
shorthand = {BR},
}
\end{filecontents}

\begin{document}

Some text \autocite{A01}.

Some text \autocite{B02}.

Some text \autocite{A01}.

\printbibliography

\end{document}

• While the cite counter is very useful for some of my scenarios, there is one caveat: It does not account for how the item is cited. Namely, the citecounter while also be larger than 1 if an entry is cited once fully, and directly afterwards with "Ibid". In that case, however, the shorthand intro should not be given in the first citation because it is never used. That problem did not occur to me when I submitted my feature request and it is a very particular problem which I think would make the cite counter overly complicated. My solution above does account for that. May 13, 2011 at 8:42
• @jjbornheim: You're of course right that my solution is not tailored to your particular formatting needs. I just wanted to provide an easy-to-use answer for future users with similar, but more general requests. May 13, 2011 at 14:50