2

My question is closely related to Customize backref similar to Wikipedia.
I am trying to obtain the same result but with the authoryear citestyle instead. This give me the following warning: Macro 'cite:comp' undefined. And as a result when I click on the arrow in the reference section the hyperlink does not work. The code I am using is:

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

Thank you in advance for your help.

moewe
  • 175,683
  • style=numeric-comp, citestyle=authoryear, sorting=nty, is quite a weird combination. Do you really want a bibliography with numbers, citations in author-year format and sorting as name > title > year. The numbering in the bibliography is kind of pointless when citations are given as author-year because the label numbers are never used. The sorting that prioritises title over year does not lend itself to your citation style that prioritises the year. Since the year is not as prominent in a numeric bib style, finding the right citation can be complicated. – moewe Nov 21 '17 at 19:49

1 Answers1

2

The answer to Customize backref similar to Wikipedia was specifically written for style=numeric-comp. Most of the code can be used for all styles, the only variable is the hyperref anchor, which must be set in the macro that prints the citation. For numeric-comp that is cite:comp, but that macro does not exist with authoryear, where we need to modify the cite macro.

So you need to replace the \renewbibmacro*{cite:comp} bit by

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

In total

\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}
moewe
  • 175,683
  • Thank you for your answer. I've tried the code you gave me but it does not work on my computer, I have an error message from biblatex because apparently the macro cite:labeldate+extradate doesn't exist. I've tried with cite:labeldate, cite:date and cite:labelyearbut I get the same error each time. Only cite:labelseemed to work but the output is incorrect and I believe it's not coherent with the ifthen loop. – aurelien Nov 22 '17 at 20:31
  • @aurelien Then you must be running an outdated version of biblatex. Update biblatex and Biber. If for some reason you can't do that, use cite:labelyear+extrayear. Depending on how old your biblatex is you might run into other problems. – moewe Nov 23 '17 at 07:59