[Tex/LaTex] Using the doi package with hyperref pagebacklinks=true

doihyperref

As best I understand it, if I want to use both the doi package and the pagebackref=true setting for hyperref, I need to load hyperref first (since otherwise doi will load it, and pagebackref=true cannot subsequently be set by \hypersetup), something like this:

\usepackage[pagebackref=true]{hyperref}
\usepackage{doi}

However, when I do this, the doi package is no longer able to escape some characters, for example, the double underscore in "COLI_a_00057" in the minimal example that follows:

\documentclass{article}
% Remove the {hyperref} line below to get this to compile
\usepackage[pagebackref=true]{hyperref}
\usepackage{doi}
\begin{document}

\cite{fort:cl11}

\begin{thebibliography}{1}

\bibitem[{Fort et~al.(2011)Fort, Adda, and Cohen}]{fort:cl11}
Fort, Karën; Gilles Adda; and K.~Bretonnel Cohen (2011).
\newblock {Amazon Mechanical Turk}: Gold mine or coal mine?
\newblock \emph{Computational Linguistics}, 37(2):413--420.
\newblock \doi{10.1162/COLI_a_00057}.

\end{thebibliography}

\end{document}

If I include this line
\usepackage[pagebackref=true]{hyperref}

I get error output like this (with a working backlink to page 1):

! Missing $ inserted.
<inserted text> 
            $
l.15 

? 
! Double subscript.
<argument> \Hy@safe@activesfalse 10.1162/COLI_a_
                                            00057
l.15 

? 
! Missing $ inserted.
<inserted text> 
            $
l.15 

If I remove it, I get a working bibliography entry with DOI link to 10.1162/COLI_a_00057 but (obviously) no backlink.

Can I use both doi and hyperref with pagebacklinks=true ?

Best Answer

The backref package that is used for the pagebackref option changes catcodes within the bibliography to find the end of bibliography entries. This breaks all stuff that relies on certain catcodes like URLs, verbatim text, and DOIs. As explained in the backref manual the catcode changes can be suspended with \backrefparscanfalse, but then it is your responsibility to tell backref where your bibliography entries end, and the page list can be written. The following works without altering the DOI:

\documentclass{article}

\usepackage[pagebackref=true]{hyperref}
\usepackage{doi}
\begin{document}

\cite{fort:cl11}

\begin{thebibliography}{1}

\backrefparscanfalse
\bibitem[{Fort et~al.(2011)Fort, Adda, and Cohen}]{fort:cl11}
Fort, Karën; Gilles Adda; and K.~Bretonnel Cohen (2011).
\newblock {Amazon Mechanical Turk}: Gold mine or coal mine?
\newblock \emph{Computational Linguistics}, 37(2):413--420.
\newblock \doi{10.1162/COLI_a_00057}.
\backrefprint\backrefparscantrue

\end{thebibliography}
\end{document}

In the likely case that you don't really setup your thebibliography environment by hand, but with the help of BibTeX and some bibliography style, please see this answer how to change the bibliography style to automatically insert the \backrefparscanfalse and \backrefprint\backrefparscantrue command before and after bibliography items.

Related Question