3

I'm using this answer to print the number of times a reference was cited. Biblatex "sees" that the reference was cited in the figure caption but it will not step up the citecounter.

The following MWE will print cited 1 time on pages 1, 2.

Does anyone have an idea why that is? I appreciate any help.

\documentclass{report}

\usepackage{filecontents}
\begin{filecontents}{references.bib}
@book{Knuth,
    author = {Knuth, Donald E.},
    title = {The Art of Computer Programming, Volume 1: Fundamental Algorithms},
    year = {1997},
    publisher = {Addison Wesley Longman Publishing Co., Inc.},
} 
\end{filecontents}

\usepackage[english]{babel}

\usepackage[backref=true,backend=biber,citecounter=true]{biblatex}
\addbibresource{references.bib}

\renewbibmacro*{pageref}
{%
    \iflistundef{pageref}
    {\printtext{\autocap{n}o citation in the text.}}
    {
        \printtext{\autocap{c}ited \arabic{citecounter} time\ifnumgreater{\value{citecounter}}{1}{s}{}}%
        \setunit{\addspace}%
        \ifnumgreater{\value{pageref}}{1}
            {\bibstring{backrefpages}\ppspace}
            {\bibstring{backrefpage}\ppspace}%
        \printlist[pageref][-\value{listtotal}]{pageref}
    }
}

\DefineBibliographyStrings{english}
{
    backrefpage  = {on page},
    backrefpages = {on pages},
}

\begin{document}
\cite{Knuth}
\newpage
\begin{figure}
    \caption{\cite{Knuth}}
\end{figure}
\printbibliography
\end{document}

1 Answer 1

4

The citation trackers (and with it also the citation counters) are disabled within floats, since floats exist outside of the normal flow of text.

This can be re-enabled by removing the patch biblatex applies to \@floatboxreset.

\documentclass{report}
\usepackage[english]{babel}
\usepackage[backref=true,backend=biber,citecounter=true]{biblatex}
\addbibresource{biblatex-examples.bib}

\makeatletter
\AtBeginDocument{%
  \patchcmd\@floatboxreset
    {\boolfalse{citetracker}%
     \boolfalse{pagetracker}}
    {}
    {}
    {\blx@err@patch{float}}}
\makeatother

\renewbibmacro*{pageref}
{%
    \iflistundef{pageref}
    {\printtext{\autocap{n}o citation in the text.}}
    {
        \printtext{\autocap{c}ited \arabic{citecounter} time\ifnumgreater{\value{citecounter}}{1}{s}{}}%
        \setunit{\addspace}%
        \ifnumgreater{\value{pageref}}{1}
            {\bibstring{backrefpages}\ppspace}
            {\bibstring{backrefpage}\ppspace}%
        \printlist[pageref][-\value{listtotal}]{pageref}
    }
}

\DefineBibliographyStrings{english}{
  backrefpage  = {on page},
  backrefpages = {on pages},
}

\begin{document}
\cite{sigfridsson}
\newpage
\begin{figure}
    \caption{\cite{sigfridsson}}
\end{figure}
\printbibliography
\end{document}

cited 2 times on pages 1, 2.


Since the behaviour is a bit confusing I opened https://github.com/plk/biblatex/issues/916

2
  • this works perfectly, thank you!
    – Jojo
    Sep 2, 2019 at 19:13
  • I can't get the word cited to capitalize after the printing of the url date. Perhaps because there is no period after the url date? I posted a MWE with this issue mentioned parenthetically in the question at this url: tex.stackexchange.com/questions/657138/…
    – Steven
    Sep 17, 2022 at 2:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .