How to elegantly break long doi field

The option ocgcolorlinks doesn't allow line breaks in links.

From hyperref's README

Experimental option ‘ocgcolorlinks’

The idea are colored links, when viewed, but printed without colors.

...

  • Main disadvantage: Links cannot be broken across lines.

In other words, it is almost the same of the option colorlinks, but with two differences.

  • colorlinks allows line breaks in links, while ocgcolorlinks doesn't;
  • colorlinks preserves colors when the document is printed, while ocgcolorlinks prints them in black.

So, what can you do to circumvent this?

Use the colorlinks option instead of ocgcolorlinks and, when you print the document, choose to print it in "black and white".

MWE:

\RequirePackage{filecontents}

\begin{filecontents}{bib.bib}
@article{baumert62,
  author = {Baumert, Leonard and Golomb, Solomon W. and Hall, Jr, Marshall},
  doi = {10.1090/S0002-9904-1962-10761-7},
  journal = {Bulletin of the American Mathematical Society},
  number = 3,
  pages = {237--238},
  title = {Discovery of an Hadamard Matrix of Order 92},
  volume = 68,
  year = 1962
}

\end{filecontents}

\documentclass{article}

% for back reference in bibliography
\usepackage[colorlinks,pdfusetitle]{hyperref}

% for biblatex with biber
\usepackage[
  backend=biber,
  style=alphabetic,
  citestyle=alphabetic,
  backref=true]{biblatex}

% for DOI field
\usepackage{doi}

\addbibresource{bib.bib}

\begin{document}
The first missing order of 92 was resolved in 1962 by Baumert, Golomb,
and Hall Jr. \cite{baumert62} who ran computer experiment on Williamson's method.

%%% bibliography
\printbibliography
\end{document} 

Output:

enter image description here


Just for completeness that ocgcolorlinks (coloured links printing as black) that wrap around linebreaks (and page breaks, if need be) are now possible with the ocgx2 package:

\usepackage{hyperref}
\usepackage[ocgcolorlinks]{ocgx2}

MWE:

\RequirePackage{filecontents}

\begin{filecontents}{bib.bib}
@article{baumert62,
  author = {Baumert, Leonard and Golomb, Solomon W. and Hall, Jr, Marshall},
  doi = {10.1090/S0002-9904-1962-10761-7},
  journal = {Bulletin of the American Mathematical Society},
  number = 3,
  pages = {237--238},
  title = {Discovery of an Hadamard Matrix of Order 92},
  volume = 68,
  year = 1962
}

\end{filecontents}

\documentclass{article}

% for back reference in bibliography
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[pdfusetitle]{hyperref}
\usepackage[ocgcolorlinks]{ocgx2}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% for biblatex with biber
\usepackage[
  backend=biber,
  style=alphabetic,
  citestyle=alphabetic,
  backref=true]{biblatex}

% for DOI field
\usepackage{doi}

\addbibresource{bib.bib}

\begin{document}
The first missing order of 92 was resolved in 1962 by Baumert, Golomb,
and Hall Jr. \cite{baumert62} who ran computer experiment on Williamson's method.

%%% bibliography
\printbibliography
\end{document}

You can use http://shortdoi.org to create a short persistent alias for the DOI, as @matth mentioned. These shortened DOIs have several advantages over the canonical DOI:

  1. They are short enough so that line breaking is not necessary.
  2. They are easy to copy from paper. A long DOI is almost useless if you only have a paper copy of an article (it's easier to just search for the title/authors).
  3. They are more aesthetically pleasing, which means less resistance from publishers and coauthors.

I wrote a script that will process an existing BibTeX file and replace all the DOI names with shortened DOIs: https://github.com/mosco/bibtex-shorten-doi

A word of caution: unfortunately short DOIs are not considered proper DOIs and cannot be used for manual lookup on any site other than doi.org, such as CrossRef, Sci-Hub, etc. So at the moment, I do not recommend automatic conversion of all the DOIs in your bibliography.