自定义类似 Wikipedia 的 backref

自定义类似 Wikipedia 的 backref

report使用 backref 选项的文档类中的引用biblatex如下所示:

在此处输入图片描述

我已将反向引用圈出来了。

如果可能的话,我想要一些更类似于维基百科或至少更精简的内容。维基百科 backref 如下所示:

图像

我再次圈出了反向引用。

这里平均能量损失

\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}

答案1

的代码numeric-comp稍微复杂一些。但是的总体思路wikipageref应该比较清楚。

\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}

在此处输入图片描述

该解决方案refsection现在具有感知能力,并使用该.aux文件在参考书目之后拾取引文。此解决方案可能需要两次 TeX 运行才能给出正确的输出。因为需要读回该文件。新代码更加模块化,并使用与原始/功能.aux非常相似的思想backrefpagerefbiblatex.

只需稍加努力,就可以更改代码以输出页码而不是字母。

相关内容