# print cited page range in bibliography

I have to print the actually cited page range of cited books in the bibliography. The suffix [10--20] should be compressed to 10 f. or 10 ff., but in the bibliography printed as p. 10--20 I've got no clue how to achieve it, I searched for commands but without result. compress page range gives only an example how to compress page ranges from 10-19 to 10-9

One possible pathway to the solution could be via this MWE:

\documentclass{scrreprt}
\usepackage[latin1]{inputenc}
\usepackage[
bibstyle=test, citestyle=test
]{biblatex}

\begin{filecontents*}{books.bib}
@BOOK{scrubs,
author = {John Dorian},
title = {How to endure girls names},
year = {2009},
edition = {8}
publisher = {Cox publishing}
}

\end{filecontents*}

\bibliography{books.bib}

\begin{document}
\cite[10--20]{scrubs}

\printbibliography
\end{document}


and my bbx-file

\newbibmacro*{begentry}{}
\newbibmacro*{finentry}{\finentry}

\DeclareBibliographyDriver{book}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{maintitle+title}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{edition}%
\newunit
\iffieldundef{maintitle}
{\printfield{volume}%
\printfield{part}}
{}%
\newunit
\printfield{volumes}%
\newunit\newblock
\usebibmacro{series+number}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{publisher+location}%
\newunit\newblock
\usebibmacro{p.}
\usebibmacro{chapter+pages}%
\newunit\newblock
\usebibmacro{date}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\usebibmacro{finentry}}

\newbibmacro*{maintitle+title}{%
\iffieldsequal{maintitle}{title}
{\clearfield{maintitle}%
\clearfield{mainsubtitle}%
{\iffieldundef{maintitle}
{}
{\usebibmacro{maintitle}%
\newunit\newblock
\iffieldundef{volume}
{}
{\printfield{volume}%
\printfield{part}%
\usebibmacro{title}%
\newunit}

\newbibmacro*{maintitle+booktitle}{%
\iffieldundef{maintitle}
{}
{\usebibmacro{maintitle}%
\newunit\newblock
\iffieldundef{volume}
{}
{\printfield{volume}%
\printfield{part}%
\usebibmacro{booktitle}%
\newunit}

\newbibmacro*{volume}{%
\printfield{volume}%
}

\newbibmacro*{series+number}{%
\printfield{series}%
\printfield{number}%
\newunit}

\newbibmacro*{publisher+location}{%
\iflistundef{publisher}
{}
\printlist{publisher}%
\printlist{location}%
\newunit}

\newbibmacro*{chapter+pages}{%
\printfield{chapter}%
\setunit{\bibpagespunct}%
\printfield{pages}%
\newunit}

\newunit\newblock
\printfield{pubstate}}

\newbibmacro*{p.}{%
\printtext{p. }}
\endinput


and my cbx-file

% $Id: test.cbx,v 1.7 2011/11/13 19:09:07 lehman stable$

\ProvidesFile{test.cbx}
[\abx@cbxid $Id: verbose-inote.cbx,v 1.7 2011/11/13 19:09:07 lehman stable$]

\providebool{bbx:subentry}

\DeclareFieldFormat{entrysetcount}{\mknumalph{#1}}
\newbibmacro*{cite}{%
\printtext[bibhyperref]{%
\printfield{prefixnumber}%
\printfield{labelnumber}%
\ifbool{bbx:subentry}
{\printfield{entrysetcount}}
{}}}

\DeclareCiteCommand{\cite}[\mkbibbrackets]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}}
{\multicitedelim}
{\usebibmacro{postnote}}
\AtEveryBibitem{\clearfield{month}}
\endinput

-

You need to distinguish between the pages you used from the book (to be printed in the bibliography) and the pages you are actually citing. For the former, use the pages field (described in the biblatex manual, section 2.2.2), for the latter use the optional argument to \cite.

The following code

\documentclass{scrartcl}
\usepackage[latin1]{inputenc}
\usepackage{biblatex}

\begin{filecontents*}{books.bib}
@BOOK{scrubs,
author = {John Dorian},
title = {How to endure girls names},
year = {2009},
edition = {8},
publisher = {Cox publishing},
pages={10--20}
}

\end{filecontents*}

\bibliography{books.bib}

\begin{document}
\cite[10f.]{scrubs}

\printbibliography
\end{document}


results in

-
Thank you. I thought of using it that way a couple of days ago and forgot it. It's not actually the solution I wanted, because I hoped to find one with Latex processing one information to two different results. Here I have to provide two informations (for citing and pages) The visible result is the same. –  ingo Aug 8 '13 at 20:12
@ingo so you want all pages you cited throughout the document to be shown in your bibliography where the pages field is usually printed?! Strictly speaking, they are two different pieces of information: one is the number of pages relevant from the book you cited, the other is the pages you're actually quoting at that point (in essence the difference between the citation and the bibliography entry ...) –  Jonathan Aug 8 '13 at 20:17
That's almost right. I only want to shown the page range of all the cites I used in my text to be shown in my bibliography. If there weren't concrete examples I wouldn't believe it, that this is actually wanted. –  ingo Aug 8 '13 at 21:28

If you really want to list all pages that you cited in the bibliography, you can collect them all in a macro and print that into your bibliography:

The following code

\documentclass{scrartcl}
\usepackage{biblatex}

\begin{filecontents*}{books.bib}
@BOOK{scrubs,
author = {John Dorian},
title = {How to endure girls names},
year = {2009},
edition = {8},
publisher = {Cox publishing},
}
\end{filecontents*}

\makeatletter
\DeclareFieldFormat{postnote}{\mkfirstpage{#1}\ifnumeral{#1}{}{\ifnumerals{#1}{f.}{}}%
\expandafter\expandafter\expandafter\gappto\expandafter%
\csname pagelist@\csfield{fullhash}\endcsname%

\renewbibmacro*{chapter+pages}{%
\printfield{chapter}%
\setunit*{\bibpagespunct}%
\expandafter\csname pagelist@\strfield{fullhash}\endcsname%
\newunit}
\makeatother

\bibliography{books.bib}

\begin{document}

\cite[10--20]{scrubs} \cite[33]{scrubs}

\printbibliography
\end{document}


yields

which is, as far as I understand, what you're looking for.

The first point to observe is that

\DeclareFieldFormat{postnote}{\mkfirstpage{#1}%
\ifnumeral{#1}{}{\ifnumerals{#1}{f.}{}}}


throws away all but the first page number specified and tests to see if a range of page numbers or a single page number was given (I found this slightly confusing at first: \ifnumerals checks if a number or range is provided, therefore the case "a single page is provided" is checked with \ifnumeral and if this is not the case, we check if #1 is a range of numbers or something completely different).

While we have access to the postnote field, we store the cited page numbers in a macro. Every occuring page number is stored in the macro \pagelist@<full hash> where <full hash> is a hash generated by biblatex that is unique to the bibliography entry.

In fact, the cited page is stored together with its formatting information, ready to be printed in the bibliography: for each citation,

\printtext[pages]{#1}\setunit*{\addcomma\addspace}


is appended to the macro. Note that the optional argument [pages] to \printtext adds the prefix "p." or "pp." to the number and \setunit* makes sure the punctuation works in accordance with biblatex's punctuation tracker (i.e. there is a full stop before the list and no trailing comma at the end).

Up to this point, we have only influenced what happens when the postnote field is printed. The next step is to insert our macro into the bibliography.

In the standard.bbx style of biblatex, the pages field is printed in the course of the bibmacro chapter+pages (this should be adapted if you write your own bibliography driver or use a different style!). In this case, we simply replace the printing of the pages field with our macro.

There are some downsides to this approach:

1. There is no sorting. The page numbers are listed in the order they are cited.

2. There is no checking for duplicates.

Both problems are not easy to solve (as far as I know ...) as handling lists in LaTeX is difficult, to say the least, and hence the outcome can be very unsatisfying. Consider for example

\cite[10--20]{scrubs} \cite[33]{scrubs} \cite[11]{scrubs}, \cite[2--3]{scrubs}

\printbibliography


which results in

which is confusing to say the least!

Therefore, the above "solution" may be seen as a fun exercise for appending values to macros but I would definitely advise using the pages field instead. If you want to emphasize which parts of the book you actually cited, the backref option is, in my opinion, a much better approach.

-
I stay with the pages field. It's easier to use. Thanks! –  ingo Aug 11 '13 at 11:33