# Counting number of references using environment or special bib-entry field

Suppose, that we write a survey. Somehow we need to count a number of reviewed papers. The simplest way is to create a counter, say, refsRev and add 1 at each \cite.

I created newcommand \rcite, which wrap \cite and adds 1 to refsRevS counter. However, it would be great to have more general decision.

One possible way of problem-solving is to create a special field in bib-entries (a field note is used for another purposes). Then if this field exists for a bib-entry (or we can check a value inside an entry), count the reference, say within citenum.

I've tried to implement another possible way of problem-solving: to create a special environment. However

1. citenum, which works fine with biblatex is broken for biber
2. I do not know how to save a number of current citings (without duplicates) at the beginning of environment and at the end of environment

As a MWE we can use a MWE given here with some modifications. Perhaps, it is possible to use somehow assoccnt package as it is done by egreg for counting chapters here

Here is my MWE:

MyBook.tex:

\documentclass[a5paper,10pt,twoside,openany,article]{memoir}
\usepackage[backend=biber,bibencoding=utf8,sorting=none,]{biblatex}[2014/06/25]

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
author = {Author, A.},
year = {2001},
title = {Alpha}
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Betta}
}
@misc{C03,
author = {Cuthor, C.},
year = {2003},
title = {Charlie}
}
@misc{D04,
author = {Duthor, D.},
year = {2004},
title = {Delta}
}
@misc{E05,
author = {Euthor, D.},
year = {2005},
title = {Eelta}
}
\end{filecontents}
\usepackage{etoolbox}
\usepackage{totcount,assoccnt}

% http://texblog.org/2012/04/16/counting-the-total-number-of/
\newtotcounter{citenum} %total counter for references %broken
\def\oldcite{}
\let\oldcite=\bibcite
\def\bibcite{\stepcounter{citenum}\oldcite}

% attempt to create an environment
\newcounter{refsRev} %counter for total citings in environment countRefs
\newcounter{atBeginOfCountRefs} % save a current number of citings at the begining of env
\newcounter{atEndOfCountRefs} % save a current number of citings at the end of env
\newenvironment{countRefs}{
% 1) save number of references at the begining and at the end of environment
% 2) calculate the differense between them
% 3) add to refsRev the current values of counters
}

% new cite-like command, seems to be safe, i.e. with the same properities as \cite[]{}
\newcounter{refsRevS}

\begin{document}
Here we need to mention that there are \therefsRev $\:$  references in some parts of text, which are wrapped by our environment countRefs.

This document contains \total{citenum} references (possibly with multiple citations). %broken
\section{First}
Some text \autocite{A01}.
\begin{countRefs}
Here we begin review papers.
Some text \autocite{B02} = \rcite{B02}
Some text \autocite{B02}. % this value should be deleted
\section{Second}
Some text \autocite{C03}.
Some text \autocite{D04}.
Here we temporary stop review papers.
\end{countRefs}
Some text \autocite{A01}.
The current number of refsRev papers is ... % 3 papers
\section{Third}
\begin{countRefs}
Continuation of papers review.
Some text \cite[p.2~]{E05} = \rcite[p.2~]{E05}
Some text \autocite{D04}.
End of papers review.
\end{countRefs}
The current number of refsRev papers is ... % 4 papers
The current number of refsRevS papers is \therefsRevS.
\end{document}


The question is how to get one of two mentioned decisions to count survey papers?

UPT: It would be great to have an opportunity to add by \rcite a citing into a counter, which is used for the environment, i.e. to mix these two approaches.

• This seems very complicated. Biber already counts the citations. Why not \immediate\write18{grep citekeys \jobname.blg | cut -d' ' -f6 > citekeys.txt} then \newread\citecnt \openin\citecnt=citekeys.txt \read\citecnt to \printcitecnt. Usage: The total number of citations is \printcitecnt. (Compile with option -shell-escape.)
– jon
Dec 11 '16 at 18:12
• There is a successor to assoccnt, named xassoccnt, but as its author, I doubt that it is useful at all for your purpose
– user31729
Dec 27 '16 at 11:05
• Dear @ChristianHupfer, thank you for the comment. The task is really hard, perhaps it is better just to use \rcite command. Dec 28 '16 at 21:17
• @VladimirParkhomenko: I am no biblatex expert, so no advice from me here. I can't say whether it is possible to implement something in xassoccnt what you request
– user31729
Jan 2 '17 at 0:47