biblatex backref 自定义为看起来像带有 authoryear 风格的维基百科

biblatex backref 自定义为看起来像带有 authoryear 风格的维基百科

我的问题与自定义类似 Wikipedia 的 backref
我尝试使用 citestyle 来获得相同的结果authoryear。这给了我以下警告:Macro 'cite:comp' undefined。因此,当我单击参考部分中的箭头时,超链接不起作用。我使用的代码是:

\documentclass[12pt]{article}
\usepackage{polyglossia}
\setdefaultlanguage{french}
\usepackage[T1]{fontenc} 
\usepackage{csquotes}
\usepackage[backend=biber,
style=numeric-comp,
citestyle=authoryear,
 sorting=nty,
natbib=true
]{biblatex}

\usepackage[xetex]{hyperref}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{filecontents}
\begin{filecontents}{biblio.bib}

@article{georgescu1971,
  title={The entropy law and the economic problem},
  author={Georgescu-Roegen, Nicholas},
  journal={Harvard University, Harvard},
  year={1971}
}
\end{filecontents}
\addbibresource{biblio.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}

The book \emph{The Enthropy Law and the Economic Process} \citep{georgescu1971} is very important to understand the theory of economic degrowth. 
\newpage

\printbibliography
\end{document}

预先感谢您的帮助。

答案1

答案自定义类似 Wikipedia 的 backref是专门为 编写的style=numeric-comp。大部分代码可用于所有样式,唯一的变量是锚点hyperref,必须在打印引用的宏中设置它。对于numeric-compcite:comp但该宏在 中不存在authoryear,我们需要修改该cite宏。

因此你需要\renewbibmacro*{cite:comp}

\renewbibmacro*{cite}{%
  \printtext[bibhypertarget]{%
    {\iffieldundef{shorthand}
       {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
          {\usebibmacro{cite:label}%
           \setunit{\printdelim{nonameyeardelim}}}
          {\printnames{labelname}%
           \setunit{\printdelim{nameyeardelim}}}%
        \usebibmacro{cite:labeldate+extradate}}
       {\usebibmacro{cite:shorthand}}}}}

总共

\documentclass[12pt]{article}
\usepackage[T1]{fontenc} 
\usepackage{csquotes}
\usepackage[backend=biber,
  style=numeric-comp,
  citestyle=authoryear,
  sorting=nty,
  natbib=true,
]{biblatex}

\usepackage{hyperref}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{georgescu1971,
  title   = {The entropy law and the economic problem},
  author  = {Georgescu-Roegen, Nicholas},
  journal = {Harvard University, Harvard},
  date    = {1971},
}
\end{filecontents}
\addbibresource{\jobname.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}{%
  \printtext[bibhypertarget]{%
    {\iffieldundef{shorthand}
       {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
          {\usebibmacro{cite:label}%
           \setunit{\printdelim{nonameyeardelim}}}
          {\printnames{labelname}%
           \setunit{\printdelim{nameyeardelim}}}%
        \usebibmacro{cite:labeldate+extradate}}
       {\usebibmacro{cite:shorthand}}}}}

\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}
The book \citetitle{georgescu1971} \citep{georgescu1971} is very important to understand the theory of economic degrowth. 
\newpage

\printbibliography
\end{document}

相关内容