2

I want to configure a conditional setup on the bibliography such that when the option backref=true is used, it should appear as:

[1] Vladimir I Arnold. Mathematical Methods of Classical Mechanics. Vol. 60. Graduate Texts in Mathematics. Springer Science & Business Media, 2013. (p. 2)

If backref=true is commented out or not enabled (default behavior):

[1] Vladimir I Arnold. Mathematical Methods of Classical Mechanics. Vol. 60. Graduate Texts in Mathematics. Springer Science & Business Media, 2013.

Here's my MWE:

\documentclass[a4paper]{report}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    linkcolor={black},
    citecolor={black},
    urlcolor={blue!80!black},
}

\usepackage[usenames,dvipsnames]{xcolor}

% bibliography
\usepackage[
    backend=biber, 
    backref=true, 
    style=numeric, 
    sortcites=true, 
    sorting=none, 
    defernumbers=true
]{biblatex}       
\usepackage{xurl}               

%% https://tex.stackexchange.com/a/606518/114006
\DefineBibliographyStrings{english}{
   backrefpage={p.},
   backrefpages={pp.}
}
\renewcommand*{\finentrypunct}{} % Need to apply the condition here.
\usepackage{xpatch}

\DeclareFieldFormat{backrefparens}{\addperiod~\raisebox{-4pt}{\scriptsize{\mkbibparens{#1}}}}
\xpatchbibmacro{pageref}{parens}{backrefparens}{}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{filecontents}{ref.bib}
@book{arnold2013mathematical,
  title = {Mathematical {{Methods}} of {{Classical Mechanics}}},
  author = {Arnold, Vladimir I},
  date = {2013},
  series = {Graduate {{Texts}} in {{Mathematics}}},
  volume = {60},
  publisher = {{Springer Science \& Business Media}}
}
\end{filecontents}

\addbibresource{ref.bib} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\cite{arnold2013mathematical}  

\printbibliography

\end{document}

2 Answers 2

2

The following does not technically work by taking into account the backref option setting (which would be difficult, because options are processed in a way that makes the final value not available in the preamble), but instead modifies the pageref bibmacro so that it sets \finentrypunct to empty if appropriate.

\documentclass[a4paper]{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[
  backend=biber,
  style=numeric,
  sortcites=true,
  sorting=none,
  defernumbers=true,
  backref=true,
]{biblatex}
\usepackage{xurl}

\usepackage{hyperref}
\hypersetup{
  colorlinks,
  linkcolor={black},
  citecolor={black},
  urlcolor={blue!80!black},
}

%% https://tex.stackexchange.com/a/606518/114006
\DefineBibliographyStrings{english}{
  backrefpage  = {p\adddot},
  backrefpages = {pp\adddot},
}

\DeclareFieldFormat{backrefparens}{\raisebox{-4pt}{\scriptsize{\mkbibparens{#1}}}}
\renewbibmacro*{pageref}{%
  \iflistundef{pageref}
    {}
    {\setunit{\finentrypunct\addnbspace}%
     \printtext[backrefparens]{%
       \ifnumgreater{\value{pageref}}{1}
         {\bibstring{backrefpages}\ppspace}
         {\bibstring{backrefpage}\ppspace}%
       \printlist[pageref][-\value{listtotal}]{pageref}}%
     \renewcommand\finentrypunct{}}}

\addbibresource{biblatex-examples.bib}

\begin{document}
\cite{sigfridsson}
\nocite{worman}

\printbibliography
\end{document}

Two bib entries: one with backref and one without. In both cases \finentrypunct is typeset at the end of the entry (before the backref).

3
  • Thank you. Why did you prefer using p\adddot instead of p.?
    – raf
    Commented May 20 at 7:45
  • 1
    @raf If we write p. biblatex thinks the . is a sentence-ending full stop/period. If we write p\adddot, biblatex knows it is a dot that marks an abbreviation. This is important for the punctuation tracking feature where we can have dot-comma, but not full stop-comma etc.
    – moewe
    Commented May 20 at 10:49
  • Thank you for the clarification!
    – raf
    Commented May 20 at 10:58
0

I have found a way to tackle the condition using \ifbacktracker. I am getting the desired output. Also, I get the default behavior when I remove the option backref=true.

\documentclass[a4paper]{report}

\usepackage{hyperref}
\hypersetup{
    colorlinks,
    linkcolor={black},
    citecolor={black},
    urlcolor={blue!80!black},
}
\usepackage[usenames,dvipsnames]{xcolor}

\usepackage[
    backend=biber, 
    style=numeric, 
    sortcites=true, 
    sorting=none, 
    defernumbers=true,
    backref=true,
]{biblatex}       
\usepackage{xurl}               

%% https://tex.stackexchange.com/a/606518/114006
\DefineBibliographyStrings{english}{
   backrefpage={p.},
   backrefpages={pp.}
}

\usepackage{xpatch}

\ifbacktracker
    \renewcommand*{\finentrypunct}{}
    \DeclareFieldFormat{backrefparens}{\addperiod\raisebox{-4pt}{\scriptsize{\mkbibparens{#1}}}}
    \xpatchbibmacro{pageref}{parens}{backrefparens}{}{}
\fi 

\addbibresource{biblatex-examples.bib}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\cite{sigfridsson}
\printbibliography

\end{document}
3
  • Checking the answer of @moewe, I found a problem with this answer. It's affecting the behavior of \nocite command. When backref=true is used, \nocite should also show the default punctuation (period) at the end of each bib entry, but it's not showing.
    – raf
    Commented May 20 at 9:26
  • 2
    This will also run into trouble if you later in the preamble do \ExecuteBibliographyOptions{backref=false} or if per-type or per-entry options are used.
    – moewe
    Commented May 20 at 10:50
  • I see... I'd better go with your solution.
    – raf
    Commented May 20 at 11:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .