1

During my last experience with Cross-referencing on total counts between different files, which can be read here, a problem of saving the total number of literature references in a user defined counter appears.

There are at least two ways to save this value in auxiliary file using:

  1. zref package given by Heiko Oberdiek, see, please, here
  2. xr and refcount packages given by Werner, see, please, here

There are at least two ways of forming total count of literature references using:

  1. totcount package given by Mike Renfro and also by Ian Thompson, see, please, here and here, respectively.
  2. \printbibliographymakro given by Maieul, see, please, here. However in this case we produce also bibliographies of difference types.

I try to get a total count of literature references by totcount and save it by zref. The problem is that command \total{citenum} returns a dirty code, e.g. \def \c@citenum@totc {\c@citenum@totc }2} for MWE, so I can not export this value to another .tex file. Note, that the last value 2 is a true value of references mentioned in a source code.

The question is how get a total number of literature references and save it to a user defined counter in a correct way? A given value should be compatible with one of the approaches to export the value to another .tex file.

The simplest way to solve the problem is to parse the following line \def \c@citenum@totc {\c@citenum@totc }2} and save symbols between last } and } in a separate counter. There can be also approaches to hack totcount or use another packages to form a total count of literature references.

MWE is a combination of this and this MWEs.

    \documentclass{report}
    % http://texblog.org/2012/04/16/counting-the-total-number-of/
    \usepackage{totcount}
    \newtotcounter{citenum}
    \def\oldcite{}
    \let\oldcite=\bibcite
    \def\bibcite{\stepcounter{citenum}\oldcite}


    \usepackage{zref-abspage, zref-lastpage}
    \makeatletter
    \zref@newprop{myreferences}[0]{\total{citenum}}
    \zref@addprops{LastPage}{myreferences}
    \makeatother



    \begin{filecontents}{\jobname.bib}
    @article {First,
    author = "FA"
    }
    @article {Second,
        author = "SA"
    }
    \end{filecontents}

    \begin{document}


    Some citations: \cite{First}, \cite{First}, \cite{Second}.
    This document contains \total{citenum} references (possibly with multiple citations).

    \bibliographystyle{plain}
    \bibliography{\jobname}

    \end{document}

A screenshot from an auxiliary file with highlighted part of text, which should be correct, i.e. there should be only value 2.

wrong format of total count of literature references

UPT: I've tried to modify Werner's solution, i.e. put \total{citenum} in the following code \setcounter{mycntr}{\total{citenum}} and got the error: Missing number, treated as zero. \setcounter{mycntr}{\total{citenum}}.

1 Answers1

2

Replace

   \zref@newprop{myreferences}[0]{\total{citenum}}

with

   \zref@newprop{myreferences}[0]{\the\totvalue{citenum}}
  • @ Piet van Oostum, thank you for this hint. It seems to work also with Werner's approach. How did you manage to find a solution? For example, how to name a counter with total citings with, which is generated by very similar command \citesnum from p.2 of [totcount package}(http://ctan.altspu.ru/macros/latex/contrib/totcount/totcount.pdf)? \the\totvalue{citesnum}? – Vladimir Parkhomenko Nov 04 '16 at 15:01
  • 1
    Well, the totcount package doc gives \totalcount for printing the total, and \totvalue for the numerical value. So I first used \totvalue, and looked in the .aux file. I saw the name of the counter there. Then \the is the logical step to get the actual value. – Pieter van Oostrum Nov 04 '16 at 15:30