9

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?

4
  • 1
    it seems to me that breaking a doi should be handled like a url, but i don't know biblatex, so can't be any more specific. Dec 19, 2014 at 14:11
  • 5
    The ocgcolorlinks option interferes. From the readme of hyperref: "Main disadvantage: Links cannot be broken across lines." Dec 19, 2014 at 16:13
  • 2
    Use colorlinks option instead of ocgcolorlinks Dec 20, 2014 at 9:27
  • 2
    Very different approach: Create a short alias DOI using shortdoi.org
    – matth
    Apr 16, 2015 at 13:20

3 Answers 3

11

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

4

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}
7
  • Don't know if there's been an update somewhere along the line, but this is not currently working in Acrobat Pro DC (2015). Links continue to print in color even with \usepackage[ocgcolorlinks]{ocgx2}.
    – kyle
    Apr 20, 2018 at 13:57
  • I will have to test this. Thank you for reporting.
    – AlexG
    Apr 20, 2018 at 14:37
  • @kyle Could you please tell us the exact version (Help->About)? I am using 2018.009.20050 which works fine.
    – AlexG
    Apr 20, 2018 at 14:43
  • The current 2018.011.20038 of Acrobat Reader works smoothly too.
    – AlexG
    Apr 20, 2018 at 15:54
  • Adobe Acrobat Pro DC (2015.006.30417). The release is I guess a few years old; I haven't upgraded since Reader Pro (with editing functionality) is an institutional purchase.
    – kyle
    Apr 20, 2018 at 16:16
2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .