# Complex formatting of page numbers (postnote) in biblatex citations

I'm trying to change the way that page numbers are displayed in biblatex citations to mimic a journal's (moderately) complex style.

The problem is that the formatting changes depending on whether the citation ends with a page range (like a full article or incollection citation) or without (like a book citation).

If the citation ends with a page range the formatting is: space|'at'|space|pagenumber. E.g:

Malcolm. ‘The Line and the Cave’ [‘Line & Cave’], Phronesis, 7 (1962), 38-45 at 38

If the citation doesn't end in a page range the formatting is: comma|space|pagenumber. E.g:

Irwin, Plato's Ethics (Oxford: Oxford University Press, 1995), 38

This much I can do using \DeclareFieldFormat to format article citations and book citations separately. BUT since the style uses shorthands for all but the first citation of an article, articles should only use the 'at' for the first citation. E.g, the second citations should be like this:

Line & Cave, 38

So what I'm trying to do is format the page reference of an article citation differently depending on whether it is the first and full citation or a subsequent and shorthand citation.

Here's a minimal working example (although I've just used the standard verbose style for simplicity):

\documentclass{article}

\begin{filecontents}{\jobname.bib}
@ARTICLE{Malcolm1962,
author = {John Malcolm},
title = {The Line and the Cave},
year = {1962},
volume = {7},
pages = {38-45},
shorthand = {Line \& Cave},
journal = {Phronesis}
}

@BOOK{Irwin1995,
author = {Terence Irwin},
title = {Plato's Ethics},
year = {1995},
publisher = {Oxford University Press},
shorthand= {Ethics}
}
\end{filecontents}

\usepackage[british]{babel}
\usepackage{csquotes}
\usepackage[style=verbose]{biblatex}

\DeclareFieldFormat{pages}{#1}
\renewcommand{\postnotedelim}{}
\DeclareFieldFormat[article, incollection]{postnote}{ at #1}
\DeclareFieldFormat[article, incollection]{multipostnote}{ at #1}
\DeclareFieldFormat[book]{postnote}{, #1}
\DeclareFieldFormat[book]{multipostnote}{, #1}

\begin{document}
\cite[38]{Malcolm1962}

\cite[101]{Irwin1995}

\cite[40-42]{Malcolm1962}%Produces 'at 40-42' when it should produce ', 40-42'
\end{document}


For the standard verbose styles this feature is already implemented by the citepages option setting:

\usepackage[style=verbose,citepages=separate]{biblatex}


Under citepages=separate the pages or pagetotal fields and postnote are separated by \postnotedelim and the bibliography string thiscite whenever the postnote is identified as a page reference via the \iffieldpages test.

Adding the following to your preamble should give you the desired result.

\DefineBibliographyStrings{english}{%
thiscite = {at}}

\renewbibmacro*{cite:postnote:pages}{%
\bibstring{thiscite}%
\printfield{postnote}}


Under other styles you can obtain the same effect by tracking when the pages field is cited and modifying the postnote bibliography macro. Here's an example that you can also add to your preamble or biblatex configuration file.

\renewbibmacro*{postnote}{%
\iffieldundef{postnote}
{}
{\ifboolexpr{
test {\iftoggle{cbx:citepages}}
and
test {\iffieldpages{postnote}}
}
\bibstring{thiscite}%
{\setunit{\postnotedelim}}%
\printfield{postnote}}}

\DeclareFieldFormat{pages}{%
#1%
\ifboolexpr{ test {\ifcitation} and not test {\ifblank{#1}} }
{\global\toggletrue{cbx:citepages}}
{}}

\newtoggle{cbx:citepages}
\AtEveryCitekey{\global\togglefalse{cbx:citepages}}


The citepages option also deals with the pagetotal field. You can extend the code to this field by similarly modifying the pagetotal formatting directive. Note that I've ignored entrytypes and just dealt with the case where the pages field is defined. You could of course consider types using the \ifentrytype test.

• That's it! Required a little fiddling for the style I'm using, but works perfectly. – D.S. Mar 16 '13 at 18:01
• @D.S. Not quite perfectly; I just noticed a bug. I'll fix it in a minute. – Audrey Mar 16 '13 at 18:24