3

References in a report document class, using biblatex with backref option, look like this:

enter image description here

where I have circled the backreference.

I want something more similar to Wikipedia or at least more condensed, if it is possible. Wikipedia backref looks like this:

image

Again I have circled the backreference.

Here a MWE

\documentclass[12pt,twoside]{report}
\usepackage[headheight=18pt,a4paper, width=150mm, top=25mm, bottom=25mm, bindingoffset=6mm, headsep=18pt]{geometry}
\usepackage[spanish,es-noquoting]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\usepackage{notoccite}
\usepackage{hyperref}
\usepackage[style=numeric-comp, backend=biber, backref=true]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@Online{Flexo,
  Title                    = {Flexo-Conformational search},
  Author                   = {M. Lavecchia},
  Url                      = {https://github.com/lavecchia/flexo},
  Year                     = {2017},

  Owner                    = {alumno},
  Timestamp                = {2017.09.02}
}

@Article{Packmol,
  Title                    = {PACKMOL: a package for building initial configurations for molecular dynamics simulations},
  Author                   = {Martínez, Leandro and Andrade, Ricardo and Birgin, Ernesto G and Martínez, José Mario},
  Year                     = {2009},
  Number                   = {13},
  Pages                    = {2157--2164},
  Volume                   = {30},

  Journal                  = {Journal of computational chemistry},
  Publisher                = {Wiley Online Library}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}

In particular we can cite \cite{Flexo} but could also be \cite{Packmol} or anything.

\printbibliography
\end{document}
TeXnician
  • 33,589

1 Answers1

8

The code for numeric-comp is a bit more complicated. But the general idea of wikipageref should be quite clear.

\documentclass[12pt,twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} 
\usepackage[spanish,es-noquoting]{babel}
\usepackage{csquotes}
\usepackage[style=numeric-comp, backend=biber]{biblatex}
\usepackage{hyperref}

\addbibresource{biblatex-examples.bib}

\makeatletter
\DeclareFieldFormat{bibhypertarget}{%
  \bibhypertarget{cbx:instcount:\the\value{instcount}}{#1}}

\def\abx@aux@wikibackref#1#2#3{%
  \listcsgadd{cbx@wikibackref@#1@#2}{#3}}

\def\blx@addwikibackref#1{%
  \if@filesw
    \protected@write\@mainaux{}{\string\abx@aux@wikibackref
       {\the\c@refsection}{#1}{\the\value{instcount}}}%
    \fi}

\def\blx@instcount@label{%
  \label{cbx@instcount@\the\value{instcount}}}

\AtEveryCitekey{%
  \blx@addwikibackref{\thefield{entrykey}}%
  \blx@instcount@label
}

\renewbibmacro*{cite:comp}{%
  \addtocounter{cbx@tempcntb}{1}%
  \printtext[bibhypertarget]{%
    \iffieldundef{shorthand}
      {\ifbool{bbx:subentry}
         {\iffieldundef{entrysetcount}
            {\usebibmacro{cite:comp:comp}}
            {\usebibmacro{cite:comp:inset}}}
         {\usebibmacro{cite:comp:comp}}}
      {\usebibmacro{cite:comp:shand}}}}

\renewbibmacro*{begentry}{\usebibmacro{wikipageref}}

\newcounter{wikibackrefitemcount}
\renewcommand{\thewikibackrefitemcount}{\alph{wikibackrefitemcount}}
\newbibmacro*{wikipageref}{%
  \ifcsundef{cbx@wikibackref@\the\c@refsection @\thefield{entrykey}}
    {}
    {\setcounter{wikibackrefitemcount}{0}%
     \renewcommand*{\do}[1]{\stepcounter{wikibackrefitemcount}}%
     \dolistcsloop{cbx@wikibackref@\the\c@refsection @\thefield{entrykey}}%
     \ifnumgreater{\value{wikibackrefitemcount}}{1}
       {\setcounter{wikibackrefitemcount}{0}%
        \renewcommand*{\do}[1]{%
          \stepcounter{wikibackrefitemcount}%
          \mkbibsuperscript{%
            \bibhyperlink{cbx:instcount:##1}{\thewikibackrefitemcount}\addspace}}%
        $\uparrow$\addspace\dolistcsloop{cbx@wikibackref@\the\c@refsection @\thefield{entrykey}}}
       {\renewcommand*{\do}[1]{\bibhyperlink{cbx:instcount:##1}{$\uparrow$}\addspace}%
        \dolistcsloop{cbx@wikibackref@\the\c@refsection @\thefield{entrykey}}}}}
\makeatother

\begin{document}
In particular we can cite \cite{sigfridsson} but could also be \cite{geer} or anything \cite{sigfridsson,nussbaum,geer}.
\clearpage
In particular we can cite \cite{sigfridsson} but could also be \cite{nussbaum} or anything.
\clearpage
In particular we can cite \cite{worman} but could also be \cite{geer} or anything \cite{sigfridsson,worman,geer,knuth:ct:a,knuth:ct:b,nussbaum}.
\clearpage
\printbibliography
\clearpage
In particular we can cite \cite{worman} but could also be \cite{geer} or anything \cite{sigfridsson,nussbaum,geer,knuth:ct:a}.
\clearpage
\newrefsection
In particular we can cite \cite{worman} but could also be \cite{geer} or anything \cite{sigfridsson,nussbaum,geer,knuth:ct:a}.
\printbibliography
\end{document}

enter image description here

The solution is refsection aware now and uses the .aux file to pick up citations after the bibliography. This solution may require two TeX runs to give the correct output., because the .aux file need to be read back. The new code is more modular and uses ideas very similar to those of the original backref/pageref feature in biblatex.

It should be possible to change the code to output the page number instead of the letter with a bit of additional effort.

moewe
  • 175,683