7

Since I am not really satisfied with how pages where a bibliographic reference is called in the text are reflected in the bibliography, I tried to modify the pageref macro in Biblatex as follows:

\documentclass{article}
\usepackage{times}
\usepackage{csquotes}
\usepackage{xcolor} 
\usepackage[style=numeric-comp,backref=true,backend=biber]{biblatex} 
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{saad00,
  title = {Iterative Methods for Sparse Linear Systems},
  year = {2000},
  author = {Y. Saad}}
\end{filecontents}

\addbibresource{\jobname.bib}

% pagereference in the right margin
\renewbibmacro*{pageref}{%
   \iflistundef{pageref}
     {}
     {\printtext{\hfill\rlap{\hskip15pt\colorbox{blue!5}{\scriptsize\printlist[pageref][-\value{listtotal}]{pageref}}}}}}

\begin{document}
text \cite{saad00}
\printbibliography
\end{document}

The problem, I think, is in the \hfill that pushes to the right a punctuation related to a previous block, the year entry in the given example. I know how to get rid of this problem by hooking the \DeclareBibliographyDriver{book} in the .bbx file but I would be happy if there is a simpler solution directly in the pageref macro.

enter image description here

lockstep
  • 250,273
pluton
  • 16,421

1 Answers1

6

Try redefining the bibmacro pageref in this way:

\renewbibmacro*{pageref}{%
   \iflistundef{pageref}
     {\renewcommand{\finentrypunct}{\addperiod}}
     {\renewcommand{\finentrypunct}{\addspace}%
      \printtext{\addperiod\hfill\rlap{\hskip15pt\colorbox{blue!5}{\scriptsize\printlist[pageref][-\value{listtotal}]{pageref}}}}}}

If pageref is undefined, the meaning of \finentrypunct is left unchanged, while when it is defined, we redefine \finentrypunct to be \addspace and we add \addperiod before \hfill. In this way it works fine even when using \nocite.

MWE:

\documentclass{article}
\usepackage{times}
\usepackage{csquotes}
\usepackage{xcolor}
\usepackage[style=numeric-comp,backref=true,backend=biber]{biblatex}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{saad00,
  title = {Iterative Methods for Sparse Linear Systems},
  year = {2000},
  author = {Y. Saad}}
\end{filecontents}

\addbibresource{\jobname.bib}

% pagereference in the right margin
\renewbibmacro*{pageref}{%
   \iflistundef{pageref}
     {\renewcommand{\finentrypunct}{\addperiod}}
     {\renewcommand{\finentrypunct}{\addspace}%
      \printtext{\addperiod\hfill\rlap{\hskip15pt\colorbox{blue!5}{\scriptsize\printlist[pageref][-\value{listtotal}]{pageref}}}}}}

\begin{document}
text \cite{saad00}
\printbibliography
\end{document} 

Output:

enter image description here

karlkoeller
  • 124,410