Problem in enabling back-referencing in classisthesis package

I am using classicthesis package version 4.1. In its manual it is written:

If you want to use backreferences from your citations to the pages they were cited on, change the following line from:

\setboolean{enable-backrefs}{false} % true false

to

\setboolean{enable-backrefs}{true} % true false

Unfortunately, the compiler does not like setting enable-backrefs to true and complains by outputting the following error messages regarding the .bbl file:

Paragraph ended before \BR@@lbibitem was complete
Illegal parameter number in definition of \Hy@tempa You meant to type ## instead of #, right?


I am using the following versions for hyperref and backref packages:

hyperref.sty   2012/11/06 v6.83m Hypertext links for LaTeX
backref.sty    2012/07/25 v1.38 Bibliographical back referencing


Could someone help me fix this problem?

The reason why those special characters in URLs do not work is the way backref works. To quote the manual:

Sometimes it is not appropriate if the entry is read as argument. For example, catcode changes for verbatim stuff do not have the desired eﬀect. Therefore the scan for the \par token can be disabled by \backrefparscanfalse before \bibitem and enabled by \backrefparscantrue afterwards.
If the scan for the end of the entry is disabled, then package backref does not know where to put the back references list. The list is printed by the macro \backrefprint, thus just call it at the right place.

And indeed, the url and hyperref packages use a lot of catcode juggling to print URLs verbatim, and this is disabled when backref takes over control of thebibliography.

egreg's solution is to put the desired catcode for # back in, with possible negative side effects. So my solution follows the advice in backref's manual. We need to change the bibliography style file for that. But this is a homegrown style anyway, so I hope you don't mind to alter it further.

In function fin.entry add one line:

FUNCTION {fin.entry}
{ add.period$write$
newline$"\backrefprint\backrefparscantrue" write$  %% added
newline$}  In function output.bibitem add one line: FUNCTION {output.bibitem} { newline$
"\backrefparscanfalse" write$newline$    %% added
"\bibitem[" write$label write$
")" make.full.names duplicate$short.list = { pop$ }
{ * }
if$"]{" * write$
cite$write$
"}" write$newline$
""
before.all 'output.state :=
}


To make this style work even when backref is not loaded, we add dummy specifications of backref's macros to the preamble by adding to function begin.bib:

FUNCTION {begin.bib}
{   preamble$empty$
'skip${ preamble$ write$newline$ }
if$"\begin{thebibliography}{" number.label int.to.str$ * "}" *
write$newline$
"\providecommand{\natexlab}[1]{#1}"
write$newline$
"\providecommand{\url}[1]{\texttt{#1}}"
write$newline$
"\expandafter\ifx\csname urlstyle\endcsname\relax"
write$newline$
"  \providecommand{\doi}[1]{doi: #1}\else"
write$newline$
"  \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi"
write$newline$
write$newline$                             %% added
write$newline$                             %% added
write$newline$                             %% added
}


The just use the modified style, without altering any bib entries.

I can propose this hack: add

\usepackage{etoolbox}
\makeatletter
\preto{\BR@bibitem}{\catcode\#=12 }
\makeatother


after the loading of hyperref and the options to backref. It may have adverse side effects, though, as doing this kind of tricks is usually dangerous.

However, the best way is to switch to biblatex that does back references in a different way.

• @@egreg: this works fine as well. May 24, 2013 at 21:11

The hints in this link solved my problem. It seems that backref conflicts with the urls that contains either % or #. Using tinyURL can solve the problem. However, this is not a complete solution as someone may like to have the actual url in the reference. I should say that it didn't fix the correct back-referencing.

That would be great if someone could address how we can have % and # in bibliography while using back-referencing.

Here is a MWE

\documentclass[
openright,
footinclude=true, cleardoublepage=empty,
BCOR=30mm, paper=letter, fontsize=11pt, % Binding correction, paper type and font size
ngerman, american, % Languages
]{scrreprt}

\PassOptionsToPackage{%
eulerchapternumbers,
listings,
pdfspacing,
subfig,
beramono,
parts}{classicthesis}

\PassOptionsToPackage{square,numbers,sort&compress}{natbib}
\usepackage{natbib}

\usepackage[position=t,singlelinecheck=off,font={it}]{subfig}

\PassOptionsToPackage{pdftex,hyperfootnotes=false,pdfpagelabels}{hyperref}
\pdfcompresslevel=9

\hypersetup{
plainpages=false, bookmarksnumbered, bookmarksopen=true, bookmarksopenlevel=1,
hypertexnames=true, pdfhighlight=/O, %
}

\usepackage{ifthen} % Allows the user of the \ifthenelse command
\newboolean{enable-backrefs} % Variable to enable backrefs in the bibliography
\setboolean{enable-backrefs}{true} % Variable value: true or false

% ---------------------------------------------------------------------------------------
\newcommand{\backrefnotcitedstring}{\relax} % (Not cited.)
\newcommand{\backrefcitedsinglestring}[1]{(Cited on page~#1.)}
\newcommand{\backrefcitedmultistring}[1]{(Cited on pages~#1.)}
\ifthenelse{\boolean{enable-backrefs}} % If backrefs were enabled
{
\PassOptionsToPackage{hyperpageref}{backref}
\usepackage{backref} % to be loaded after hyperref package
\renewcommand{\backreftwosep}{ and~} % separate 2 pages
\renewcommand{\backreflastsep}{, and~} % separate last of longer list
\renewcommand*{\backref}[1]{}  % disable standard
\renewcommand*{\backrefalt}[4]{% detailed backref
\ifcase #1
\backrefnotcitedstring
\or
\backrefcitedsinglestring{#2}
\else
\backrefcitedmultistring{#2}
\fi}
}{\relax}

\usepackage{classicthesis}

\begin{document}
This is test for back-referencing. \citep{chdkiller}.

\bibliographystyle{abbrvunsrtnat}

\bibliography{Bibliography}

\end{document}


Here is the file content of the bibliography file.

@misc{chdkiller,
author = {},
title = {{Centers for Disease Control and Prevention. Vital Statistics Public Use
Data Files - 2008 Mortality Multiple Cause Files}},
howpublished = "\url{http://www.cdc.gov/nchs/data_access/Vitalstatsonline.htm#Mortality_Multiple}",
year = {2012},
note = "[Online; accessed March 7, 2012]"
}


If I remove # from the url in the bibliography file, it will work. I am using the bibliography style file, abbrvunsrtnat.bst, posted here. It seems backref package does not like % and # in the urls.

• I'm using Zotero, which does the bib thing for me. I had a doi with a underscore. By \_` in the Zotero Doi solved my problem. There where only 2 entries I had to monipulate. So for small things, and when you in the END of your work and time is running out, this is the best solution you can find! Mar 8, 2018 at 10:03