hyperref pagebackref option for singular reverse citation (backpointer) case. pages vs page

I would like to customize the macros provided with the hyperref+backref packages to take into account the number of citations in the leading text before each back reference list.

The macro \backrefpagesname{-> pages} allowed me to have " -> pages i, iv, 15" back reference text, but how can I adapt it to "-> page X" for entries with only one back reference? I'd rather not do "-> page(s)".

This is what I have:

\usepackage[bookmarks,bookmarksnumbered,%
pdfborder={0 0 0},
pagebackref,
]{hyperref}

\renewcommand\backrefpagesname{$$\rightarrow$$ pages}
\renewcommand\backref{\backrefpagesname\ }


Sample Output

Here is a sample of my bibliography. In the second entry, it displays "-> pages" (plural) despite the single back reference.

Environment

I use the standard packages that come with Ubuntu 16.04LTS:

• hyperref 2012/11/06 v6.83m.
• backref (included by hyperref) 2012/07/25 v1.38.

Customize the list of citation page numbers for consecutive pages: how to modify backrefalt with selfmade tex command (unanswered)

I've found a solution inspired by an example in the backref package manual. I've deleted my redefinitions of \backrefpagesname and \backref and opted for a different set of macros that provide the number of citations as arguments, i.e. \backrefalt. I'm still using hyperref (and the backref package that it includes).

I've modified my main document file to have the following macros:

\usepackage[bookmarks,bookmarksnumbered,%
pdfborder={0 0 0},
pagebackref,
]{hyperref}

%...

% adapt back reference leading text to account for number of citations
%
%\renewcommand*{\backref}[1]{}% for backref < 1.33 necessary
\renewcommand*{\backrefsep}{,~}%
\renewcommand*{\backreftwosep}{,~}% ', and~'
\renewcommand*{\backreflastsep}{,~}% ' and~'

\renewcommand*{\backrefalt}[4]{%
\ifcase #1 %
No citations.%
\or
$$\rightarrow$$ page #2%
\else
$$\rightarrow$$ pages #2%
\fi
}


The default \backrefXsep macros inserted "x, and y and z" inside each list. To preserve the look of my original document, I've redefined those to use just commas.

The final output looks like the following:

If you'll notice, there is a "No citations" case. It doesn't show up in my final document because the bibliography only displays items that are cited at least once, but it does pop up in the intermediary stages of compilation (i.e. between runs of pdflatex/bibtex), so you'll probably need a placeholder for it regardless.

• You could accept the answer to mark the question as solved. – Bobyandbob Feb 21 '18 at 22:30