[Tex/LaTex] bibtex: URL and DOI line breaks on different characters

bibtexdoihyperrefline-breaking

In my references, I want to allow DOI's to break on a slash '/' character (or as a last resort on any character) to avoid underfull lines like the third reference below. Note that URL's are already breaking on slashes, and DOI's are already breaking on dashes.

image with problematic entry

\documentclass{article}

\usepackage[left=1.5in,right=1.5in]{geometry}

\usepackage{natbib}
\usepackage[colorlinks,breaklinks,urlcolor=blue]{hyperref}
\usepackage{doi}
\urlstyle{rm}
\bibliographystyle{sp}

\begin{document}
\nocite{Endriss:09} \nocite{Evans:80} \nocite{Szabolcsi:10}
\bibliography{references}
\end{document}

Here are some .bib entries:

@article{Evans:80, Author={Gareth Evans}, Journal={Linguistic Inquiry}, Number={2},
    Pages={337--362}, Title={Pronouns}, Url={http://www.jstor.org/stable/4178164},
    Volume={11}, Year={1980}}

@book{Szabolcsi:10, Author={Anna Szabolcsi}, Doi={10.1017/CBO9780511781681},
    Publisher={Cambridge University Press}, Title={Quantification}, Year={2010}}

The bibliography style file can be downloaded as part of a zip file (containing also the actually used class file) here: Instructions for S&P authors using LATEX 2ε | von Fintel | Semantics and Pragmatics.

Best Answer

If you want the “doi:” also in roman font, as it seems to me, you need to replace the package doi with an own command \doi declared with url’s own facilities. It doesn’t matter, that it’s already defined in the class file sp.cls. Otherwise you could also use the package uri. Compare also my answer here: Produce a hyperlinked DOI?.

\documentclass{sp} % based on "article"

\usepackage[left=1.5in,right=1.5in]{geometry}

\usepackage{filecontents}
% will produce a BIB file with the same name like your main tex file
\begin{filecontents*}{\jobname.bib}
@article{Evans:80,
  Author={Gareth Evans},
  Journal={Linguistic Inquiry},
  Number={2},
  Pages={337--362},
  Title={Pronouns},
  Url={http://www.jstor.org/stable/4178164},
  Volume={11}, Year={1980}
}
@book{Szabolcsi:10,
  Author={Anna Szabolcsi},
  Doi={10.1017/CBO9780511781681},
  Publisher={Cambridge University Press},
  Title={Quantification},
  Year={2010}
}
\end{filecontents*}

\usepackage{natbib} % actually not needed: already defined in the class "sp"
\bibliographystyle{sp} % actually not needed: already defined in the class "sp"


% already loaded with the class "sp", throws out an error, if separately loaded:
% \usepackage[colorlinks,breaklinks,urlcolor=blue]{hyperref} % loads "url"
%
\urlstyle{rm} % actually not needed: already defined in the class "sp"
% see the documentation of "url" for the next command
% "doi:" is not part of the link:
\DeclareUrlCommand\doi{\def\UrlLeft##1\UrlRight{doi:\href{http://dx.doi.org/##1}{##1}}\urlstyle{rm}}
% "doi:" is part of the link:
% \DeclareUrlCommand\doi{\def\UrlLeft##1\UrlRight{\href{http://dx.doi.org/##1}{doi:##1}}\urlstyle{rm}}

\begin{document}
\nocite{Evans:80} \nocite{Szabolcsi:10}
\bibliography{\jobname}
\end{document}