4

On the question Formatting back references in bibliography [BibTeX] I learned how to do this for bibtex with the backref package:

\usepackage[pagebackref=true]{hyperref}
\renewcommand*{\backref}[1]{}
\renewcommand*{\backrefalt}[4]
{
    \ifcase #1
        No citation in the text.
    \or
        Cited on page #2.
    \else
        Cited #1 times on pages #2.
    \fi
}

Example:

% How does 'filecontents' keep LaTeX parsing while temporarily stop writing output
% https://tex.stackexchange.com/questions/104159/how-does-filecontents-keep-latex
\RequirePackage{filecontents}

\begin{filecontents*}{references.bib}
@mvbook{assis08,
    author = {Machado de Assis},
    title = {Obra completa em quatro volumes},
    year = {2008},
    editor = {Aluizio Leite and Ana Lima Cecilio and Heloisa Jahn},
    editortype = {organizer},
    edition = {2},
    volumes = {4},
    publisher = {Nova Fronteira},
    location = {Rio de Janeiro},
    series = {Biblioteca luso-brasileira. Série brasileira}
}

@book{koma-scrguien,
  author = {Markus Kohm},
  edition = {2017-04-13},
  howpublished = {\url{http://mirrors.ibiblio.org/CTAN/.../scrguien.pdf}},
  publisher = {Online Material; \url{https://www.ctan.org/pkg/koma-script}},
  title = {The Guide KOMA -Script},
  urlaccessdate = {2017-08-28},
  year = {2017}
}
\end{filecontents*}


% How to make \PassOptionsToPackage add the option as the last option?
% https://tex.stackexchange.com/questions/385895/how-to-make
\PassOptionsToPackage{brazil,main=english}{babel}
\documentclass{abntex2}

% An alternative to utf8 and arabtex under memoir documentclass
% https://tex.stackexchange.com/questions/42566/an-alternative-to-utf8-and-arabtex
\makeatletter
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}
\DeclareOldFontCommand{\sl}{\normalfont\slshape}{\@nomath\sl}
\DeclareOldFontCommand{\sc}{\normalfont\scshape}{\@nomath\sc}
\makeatother

% backreferencing in classicthesis package does not work
% https://tex.stackexchange.com/questions/115828/backreferencing-in-classicthesis
\usepackage[english,hyperpageref]{backref}

% Citação alfabética por autor-data [alf]
\usepackage[alf]{abntex2cite}

% Package hyperref Warning: Token not allowed in a PDF string?
% https://tex.stackexchange.com/questions/384885/package-hyperref
\pdfstringdefDisableCommands{\let\uppercase\relax}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

% Package biblatex Warning: 'babel/polyglossia' detected but 'csquotes' missing
% https://tex.stackexchange.com/questions/229638/package-biblatex-warning
\usepackage{csquotes}

% Default text before page number
\renewcommand{\backref}{}
\renewcommand{\backrefpagesname}{Cited on page(s):~}

% Sets the text of the citation
\renewcommand*{\backrefalt}[4]
{
    \ifcase #1
        No citation in the text.
    \or
        Cited on page #2.
    \else
        Cited #1 times on pages #2.
    \fi
}

\begin{document}

    Citing \cite{koma-scrguien}, \newpage Citing again \cite{koma-scrguien},

    % \nocite{*}
    \bibliography{references}

\end{document}

enter image description here

However now I migrated to biblatex looking for a state-of-the-art bibliography package, but I could not figure it out on how to do it. For now with the question Formatting back references in bibliography I was able to do:

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

But when the bibliography is not cited, I got no text saying Not cited or saying Cited #1 times on pages #2.

% How does 'filecontents' keep LaTeX parsing while temporarily stop writing output
% https://tex.stackexchange.com/questions/104159/how-does-filecontents-keep-latex
\RequirePackage{filecontents}

\begin{filecontents*}{references.bib}
@mvbook{assis08,
    author = {Machado de Assis},
    title = {Obra completa em quatro volumes},
    year = {2008},
    editor = {Aluizio Leite and Ana Lima Cecilio and Heloisa Jahn},
    editortype = {organizer},
    edition = {2},
    volumes = {4},
    publisher = {Nova Fronteira},
    location = {Rio de Janeiro},
    series = {Biblioteca luso-brasileira. Série brasileira}
}

@book{koma-scrguien,
  author = {Markus Kohm},
  edition = {2017-04-13},
  howpublished = {\url{http://mirrors.ibiblio.org/CTAN/.../scrguien.pdf}},
  publisher = {Online Material; \url{https://www.ctan.org/pkg/koma-script}},
  title = {The Guide KOMA -Script},
  urlaccessdate = {2017-08-28},
  year = {2017}
}
\end{filecontents*}


% How to make \PassOptionsToPackage add the option as the last option?
% https://tex.stackexchange.com/questions/385895/how-to-make
\PassOptionsToPackage{brazil,main=english}{babel}
\documentclass{abntex2}

% Package hyperref Warning: Token not allowed in a PDF string?
% https://tex.stackexchange.com/questions/384885/package-hyperref
\pdfstringdefDisableCommands{\let\uppercase\relax}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[style=abnt,language=english,backref=true,backend=biber]{biblatex}
\addbibresource{references.bib}

% Package biblatex Warning: 'babel/polyglossia' detected but 'csquotes' missing
% https://tex.stackexchange.com/questions/229638/package-biblatex-warning
\usepackage{csquotes}

% Sets the text of the citation
% \renewcommand*{\backrefalt}[4]
% {
%     \ifcase #1
%         No citation in the text.
%     \or
%         Cited on page #2.
%     \else
%         Cited #1 times on pages #2.
%     \fi
% }

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

\begin{document}

    Citing \cite{koma-scrguien}, \newpage Citing again \cite{koma-scrguien},

    \nocite{*}
    \printbibliography

\end{document}

enter image description here

7

With the citecounter option we can access the number of times an entry was cited, see Can I count the number of times each reference is cited?. We can redefine the macro for back references to include this info

\renewbibmacro*{pageref}{%
  \iflistundef{pageref}
    {\printtext{\autocap{n}ot cited}}
    {\printtext{\autocap{c}ited \arabic{citecounter}~time\ifnumequal{\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},
}
0

Posting minimal example based on @moewe answer, noticing we need to pass the option citecounter=true to the biblatex package, otherwise the references counter will always show 0 times cited on pages ...:

% How does 'filecontents' keep LaTeX parsing while temporarily stop writing output
% https://tex.stackexchange.com/questions/104159/how-does-filecontents-keep-latex
\RequirePackage{filecontents}

\begin{filecontents*}{references.bib}
@mvbook{assis08,
    author = {Machado de Assis},
    title = {Obra completa em quatro volumes},
    year = {2008},
    editor = {Aluizio Leite and Ana Lima Cecilio and Heloisa Jahn},
    editortype = {organizer},
    edition = {2},
    volumes = {4},
    publisher = {Nova Fronteira},
    location = {Rio de Janeiro},
    series = {Biblioteca luso-brasileira. Série brasileira}
}

@book{koma-scrguien,
  author = {Markus Kohm},
  edition = {2017-04-13},
  howpublished = {\url{http://mirrors.ibiblio.org/CTAN/.../scrguien.pdf}},
  publisher = {Online Material; \url{https://www.ctan.org/pkg/koma-script}},
  title = {The Guide KOMA -Script},
  urlaccessdate = {2017-08-28},
  year = {2017}
}

\end{filecontents*}


% How to make \PassOptionsToPackage add the option as the last option?
% https://tex.stackexchange.com/questions/385895/how-to-make
\PassOptionsToPackage{brazil,main=english}{babel}
\documentclass[10pt,a5paper,twoside,chapter=TITLE,section=TITLE]{abntex2}

% Package hyperref Warning: Token not allowed in a PDF string?
% https://tex.stackexchange.com/questions/384885/package-hyperref
\pdfstringdefDisableCommands{\let\uppercase\relax}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

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

% Package biblatex Warning: 'babel/polyglossia' detected but 'csquotes' missing
% https://tex.stackexchange.com/questions/229638/package-biblatex-warning
\usepackage{csquotes}

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

    Citing \textcite[p. 47-52 e 135]{koma-scrguien}

    \newpage

    Citing again \cite{koma-scrguien}

    \nocite{*}
    \printbibliography

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.