2

There are many questions about how to get URLs and DOIs in bibliographies to break properly. (This one seems like it should help, but I don't see how to use it.

My DOIs are breaking correctly, but I'm not happy with the result and want to try an alternative.

I would like it if my DOIs were shunted to a new line if they would cause a linebreak, but not if they would then still fill up the entire line, since that doesn't improve the situation.

I've been told that the answer to this question can be adapted, but I'm not sure how to work that into the bibliography to be honest. (Or, indeed what most of the code is doing in it, it has a lot of definitions and no documentation.)

Here is an example that generates a DOI that splits over a line, but doesn't need to if it was on a new line. Then the same total number of lines would be used, but it would be easier to copy/paste the DOI (if for example, my hyperlinks wound up broken by a PDF processing program down the line, which I've seen happen before when someone wants to mass-insert a copyright page or something).

\documentclass[letter]{article}
\usepackage[left= 4 cm, right=4 cm]{geometry}

\begin{filecontents}{MWE.bib} @inproceedings{Meshlab, booktitle = {Eurographics Italian Chapter Conference}, editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra}, title = {{MeshLab: an Open-Source Mesh Processing Tool}}, author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido}, year = {2008}, publisher = {The Eurographics Association}, ISBN = {978-3-905673-68-5}, DOI = {10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/129-136} } \end{filecontents}

\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}

\usepackage[ backend=biber, style=chem-rsc, doi=true, articletitle=true, pageranges=true, ]{biblatex}

\def\UrlFont{\rm} %Make the URL font roman instead of typewriter, so DOI in body and bib are the same size.

\addbibresource{MWE.bib}

\begin{document} \begin{itemize} \item DOI = {10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/129-136}\autocite{Meshlab} \end{itemize}

\printbibliography

\end{document}

Canageek
  • 17,935
  • Maybe that's enough to add a clickable short link like the term "DOI" pointing to the right page? Like \href{10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/129-136}{DOI}? All this very long DOI information seems useless to me. – pluton Oct 17 '20 at 10:33
  • 1
    Instead of \def\UrlFont{\rm} I'd say \urlstyle{same}, that's the interface the url documentation suggests for the easy cases. (Of course that has nothing to do with your actual question, but might still be interesting.) – moewe Oct 17 '20 at 12:57
  • @pluton The advantage of using a text DOI is that if the main server goes offline (which has happened) the chemistry community maintains backups, so you can still get to the paper without a lot of work. – Canageek Nov 26 '20 at 00:08

2 Answers2

4

Here's a couple of options:

1. Make your bibliography \raggedright

Just add \AtBeginBibliography{\raggedright} to you preamble.

MWE

\documentclass{article}

\usepackage[left= 4 cm, right=4 cm]{geometry}

\begin{filecontents}[overwrite]{\jobname.bib} @inproceedings{Meshlab, booktitle = {Eurographics Italian Chapter Conference}, editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra}, title = {{MeshLab: an Open-Source Mesh Processing Tool}}, author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido}, year = {2008}, publisher = {The Eurographics Association}, ISBN = {978-3-905673-68-5}, DOI = {10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/129-136} } @inproceedings{Meshlab2, booktitle = {Eurographics Italian Chapter Conference}, editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra}, title = {{MeshLab: an Open-Source Mesh Processing Tool}}, author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido}, year = {2008}, publisher = {The Eurographics Association}, ISBN = {978-3-905673-68-5}, DOI = {10.2312/LocalChapterEvents/ItalChap} } @inproceedings{Meshlab3, booktitle = {Eurographics Italian Chapter Conference}, editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra}, title = {{MeshLab: an Open-Source Mesh Processing Tool}}, author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido}, year = {2008}, publisher = {The Eurographics Association}, ISBN = {978-3-905673-68-5}, DOI = {10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/ItalianChapConf2008/129-136} } \end{filecontents}

\usepackage[ style=chem-rsc, doi=true, articletitle=true, pageranges=true, ]{biblatex}

\def\UrlFont{\rm}

\addbibresource{\jobname.bib}

\AtBeginBibliography{\raggedright}

\begin{document} \nocite{*} \printbibliography \end{document}

output

2. Encourage a break before the DOI.

You can set the DOI field format using some code slightly modified from the TeX Book to encourage a break before it:

\DeclareFieldFormat{doi}{%
  \nobreak\hfil\penalty50\hbox{}\nobreak
  DOI\addcolon\addnbspace
  \ifhyperref
    {\href{https://doi.org/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}

The \hfil creates a space if the DOI does fit on the final line, so we try and mitigate this with an \hfill at the end of the record:

\renewbibmacro{finentry}{\finentry\hfill\null}

MWE

\documentclass{article}

\usepackage[left= 4 cm, right=4 cm]{geometry}

\begin{filecontents}[overwrite]{\jobname.bib} @inproceedings{Meshlab, booktitle = {Eurographics Italian Chapter Conference}, editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra}, title = {{MeshLab: an Open-Source Mesh Processing Tool}}, author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido}, year = {2008}, publisher = {The Eurographics Association}, ISBN = {978-3-905673-68-5}, DOI = {10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/129-136} } @inproceedings{Meshlab2, booktitle = {Eurographics Italian Chapter Conference}, editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra}, title = {{MeshLab: an Open-Source Mesh Processing Tool}}, author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido}, year = {2008}, publisher = {The Eurographics Association}, ISBN = {978-3-905673-68-5}, DOI = {10.2312/LocalChapterEvents/ItalChap} } @inproceedings{Meshlab3, booktitle = {Eurographics Italian Chapter Conference}, editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra}, title = {{MeshLab: an Open-Source Mesh Processing Tool}}, author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido}, year = {2008}, publisher = {The Eurographics Association}, ISBN = {978-3-905673-68-5}, DOI = {10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/ItalianChapConf2008/129-136} } \end{filecontents}

\usepackage[ style=chem-rsc, doi=true, articletitle=true, pageranges=true, ]{biblatex}

\def\UrlFont{\rm}

\addbibresource{\jobname.bib}

\DeclareFieldFormat{doi}{% \nobreak\hfil\penalty50\hbox{}\nobreak DOI\addcolon\addnbspace \ifhyperref {\href{https://doi.org/#1}{\nolinkurl{#1}}} {\nolinkurl{#1}}}

\renewbibmacro{finentry}{\finentry\hfill\null}

\begin{document} \nocite{*} \printbibliography \end{document}

output

David Purton
  • 25,884
  • I'm getting a lot of issues with this answer. It appears to work pretty much only in the specific MWE above, if the length of the text other then the DOI changes I get the DOI moving to a new line despite lots of space being left, or a big chunk of whitespace before the DOI.

    Should I add these to the MWE above with an image?

    – Canageek Oct 16 '20 at 21:18
  • 1
    @Canagreek, I would have thought the ragged right option would be reliable. But add some other examples and see if you get a better answer. I can look at it again too. – David Purton Oct 16 '20 at 23:16
  • @Canageek Well, \raggedright does a little more than just change your DOIs. It effectively turns off justification (in Word terms is switched from 'justify' to 'align left'). This may indeed be a bit excessive if you only wanted to influence the DOI, but given your other recent questions where you ask about disabling a few other break points giving up justification (i.e. going with \raggedright) may be your only option if you don't want to be stuck with many massively overfull or overfull boxes. – moewe Oct 17 '20 at 12:56
  • 1
    @Canageek, ah yes. I didn't think carefully enough about shorter DOIs. the \hfil is responsible for the big white space. :( – David Purton Oct 17 '20 at 14:22
  • @Canageek, it's a bit of a hack, but what if you add \renewbibmacro{finentry}{\finentry\hfill\null} to your preamble? – David Purton Oct 17 '20 at 14:34
  • Sorry, I didn't try the ragged right, I was talking about the second option, I like the justification. – Canageek Oct 17 '20 at 16:27
0

Here's what I do:

\documentclass{article}
\usepackage[left= 4 cm, right=4 cm]{geometry}

\begin{filecontents}{MWE.bib} @inproceedings{Meshlab, booktitle = {Eurographics Italian Chapter Conference}, editor = {Vittorio Scarano and Rosario De Chiara and Ugo Erra}, title = {{MeshLab: an Open-Source Mesh Processing Tool}}, author = {Cignoni, Paolo and Callieri, Marco and Corsini, Massimiliano and Dellepiane, Matteo and Ganovelli, Fabio and Ranzuglia, Guido}, year = {2008}, publisher = {The Eurographics Association}, ISBN = {978-3-905673-68-5}, DOI = {10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/129-136} } \end{filecontents}

\usepackage[T1]{fontenc} \usepackage{lmodern}

\usepackage[ backend=biber, style=chem-rsc, doi=true, articletitle=true, pageranges=true, ]{biblatex}

\renewcommand\UrlFont{\sffamily} %\renewcommand\UrlFont{\ttfamily\small} \newcommand*\doi[1]{{\UrlFont #1}}

\renewcommand*\bibsetup{\raggedright} \DeclareFieldFormat{doi}{% \mkbibacro{DOI}\addcolon\addnbspace \ifhyperref {\href{https://doi.org/#1}{\nolinkurl{#1}}} {\nolinkurl{#1}}}

\addbibresource{MWE.bib}

\begin{document} \begin{itemize} \item DOI = \doi{10.2312/LocalChapterEvents/ItalChap/ItalianChapConf2008/129-136}\autocite{Meshlab} \end{itemize}

\printbibliography

\end{document}

MWE output

That is:

  • Make the bibliography \raggedright.
  • Forbid a line break between "DOI:" and the DOI. For this, I copied the definition of the doi field format from biblatex.def and replaced \space with \addnbspace. (This is not necessary to prevent the DOI from breaking, but I find it much nicer for the "DOI:" to also move to the next line.)

Further recommendations:

  • I like to use either \ttfamily\small (which fits nicer with the default roman font than just \ttfamily) or \sffamily (which matches the overwhelmingly dominant use of sans serif fonts online) for URLs.
  • Instead of making the URL font match your normal font, you can just print DOIs in URL font everywhere.
  • Another option could be to print the bibliography in a slightly smaller font than the rest of the document (e.g. 10pt instead of 11pt), making fewer line breaks necessary overall. Be very careful with this, though.
schtandard
  • 14,892