[Tex/LaTex] How to elegantly break long doi field

biblatexdoiline-breaking

This is a code snippet from my paper.

\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[ocgcolorlinks,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}

It generates a bibliography item whose DOI field is too long.

enter image description here

Naturally, I guess everyone wants to fix it.
I know that I can use the following as explained in this thread.

\setcounter{biburlnumpenalty}{100}  % allow breaks at numbers
\setcounter{biburlucpenalty}{100}   % allow breaks at uppercase letters
\setcounter{biburllcpenalty}{100}   % allow breaks at lowercase letters

Instead of allowing linebreaks at numbers, lowercase letters and uppercase letters, I'd like to allow linebreaks at special characters such as /, . and -. As I'm dealing with DOI field, I think these are more appropriate places to allow linebreaks rather than ordinary alphanumeric characters. How can I do that?

Best Answer

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