# Using the doi package with hyperref pagebacklinks=true

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}

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 ?

• If you're looking for a quick solution; escape the underscores, they are causing problems for hyperref. hyperref apparently removes whatever it is the package doi is doing to the contents and parses them in a normal way, i.e. underscores _ only allowed in math mode hence the missing \$. So this will run fine \doi{10.1162/COLI\_a\_00057} but someone will probably come up with a better answer and explain it better than I did! – abdulhaq-e Apr 2 '13 at 5:46

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