TransWikia.com

Double Custom Backref-Text whilst Using natbib or natbibapa with apacite

TeX - LaTeX Asked on February 7, 2021

When I use natbibapa with apacite and insert backrefs, the custom text in the backref doubles as in this picture.

MWE

Any ideas, how to solve the problem?
Thanks!

Here’s a MWE:

documentclass[11pt,a4paper]{article}
usepackage[pagebackref=true]{hyperref} 
%OR usepackage{backref}
renewcommand*{backref}[1]{Zitiert auf S.{,}#1.}
usepackage[natbibapa]{apacite}
%usepackage{natbib}
RequirePackage{filecontents}
begin{filecontents}{jobname.bib}
@book{aaas1990,
 author = {{American Association for the Advancement of Science [AAAS]}},
 year = {1990},
 title = {{Science for all Americans}},
 address = {New York},
 publisher = {{Oxford University Press}},
 key = {AAAS}
}
end{filecontents}

begin{document}
I cite citep{aaas1990}. %Problem occurs independent of the use of cite{}, citep{} or anything else.
bibliography{jobname}
bibliographystyle{apacite}

end{document}
  • Problem occurs both with backref-option of hyperref or backref-package.
  • Problem occurs both with natbibapa-option of apacite or natbib-package.

One Answer

Replace renewcommand*{backref}[1]{Zitiert auf S.{,}#1.} with renewcommand*{backrefxxx}[3]{Zitiert auf S.{,}#1.}.

You can also add the following lines to the preamble to see that the command backref is called twice (I do not know why), but the first time round, its parameter is empty; the second time, the parameter contains the output of backrefxxx:

usepackage{xcolor}
renewcommand*{backref}[1]{textcolor{red}{BACKREF[1=#1]ENDOFBACKREF}}
renewcommand*{backrefxxx}[3]{textcolor{blue}{XXX[1=#1][2=#2][3=#3]ENDOFXXX}}

arguments of backref and backrefxxx

A more elaborate replacement for backref is called backrefalt:

usepackage{xcolor}
renewcommand*{backref}[1]{}   %% documentation says: use this when backref package version < 1.33
   %% I have 1.38 and when backrefalt is defined, it replaces backref
renewcommand*{backrefxxx}[3]{textcolor{blue}{XXX[1=#1][2=#2][3=#3]ENDOFXXX}}
renewcommand*{backrefalt}[4]{textcolor{green}{ALT[1=#1][2=#2][3=#3][4=#4]ENDOFALT}}

arguments of backrefalt and backrefxxx

Notice that the 1st and 3rd argument passed to backrefalt are the number of citations (#1 is number of different backreferenced pages, #3 the total number of citations). Notice how with the following definition, nothing is output if #1=0 (the first call of backrefalt above):

renewcommand*{backrefalt}[4]{%
  ifcase #1 {}%    %% do not output anything if the first argument is 0!!!
  or     page #2%  %% first argument=1   => was cited on a single page
  else   pages #2% %% first argument>1   => was cited on multiple pages
  fi
}

Answered by Ansa211 on February 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP