# Adding line break to bibliography with long numerical doi

I am generating a publication list and have a problem about the line break in a bibentry, see below:

I want the text to be aligned on the right edge and there should be a line break inserted among those zeros. This is a deliberately constructed example. The real life case also contains a doi with a long number at the end, and looks ugly without the line break. This is not a problem of the hyperlink or url package; I can also see it with a long page number at the end of a line.

So my question is how do I insert a line break here. I am using bibtex with plain and abbrev styles. I can accept a solution that customizes plain.bst or abbrev.bst.

Here is the example. I do not think it is minimal, but I also want the solution to be compatible with other packages loaded. Notice that I entered the doi in the note field, so that the plain style can display doi.

Thanks!

compiling sequence:

latex mwe.tex
bibtex mew.tex
latex mwe.tex


mwe.tex:

\documentclass[12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{anyfontsize}
\usepackage[compact]{titlesec}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{showexpl}
\usepackage{enumitem}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage[autostyle, english = american]{csquotes}
\MakeOuterQuote{"}
\usepackage{seqsplit}

% to avoid crash of hyperlink and bibentry
\usepackage{bibentry}
\makeatletter\let\saved@bibitem\@bibitem\makeatother
\makeatletter\let\@bibitem\saved@bibitem\makeatother

\usepackage{hanging}
\newcommand\publication[1]{%
\smallskip\par\hangpara{1.5em}{1}\bibentry{#1}\smallskip
}

\begin{document}

% bibliography
\bibliographystyle{abbrv}
% \bibliographystyle{plain}
\nobibliography{mwe}

\begin{enumerate}
\item \publication{test}
\end{enumerate}

\end{document}


mwe.bib

@article{test,
title = {The annoying Bibtex problem: why the line break is not inserted properly?},
volume = {1},
number = {1},
journal = {Journal},
note = {\href{http://dx.doi.org/10.0000/Journal.000000000000000000000000000000000000000000000000000000000000}{doi: 10.0000/Journal.000000000000000000000000000000000000000000000000000000000000}},
author = {\underline{John Walker} and Smith, Adam},
month = Jan,
year = {2020},
pages = {1000}
}


# Update 1

Don Hosek gave two solutions. (Thanks by the way)

1. \sloppy I use the following commands in place of the enumeration environment
\sloppy
\emergencystretch=1em

\begin{enumerate}
\item \publication{test}
\end{enumerate}


And here is the result

You can see that it does solve the problem of line breaking, but more like in a way of Microsoft Word rather than LaTeX.

1. manually add \allowbreak This is not an automated solution. I will update the reference from Zotero regularly, and I will need to insert \allowbreak every time. The place to insert \allowbreak may be different between plain and abbrev styles.

While it could solve the problem, I feel the solution is not automated.

# Update 2

Guido's solution (adopted from Mico) solves my problem.

\usepackage{xurl}


and enclose the url in \url

note = {\href{http://dx.doi.org/10.0000/Journal.000000000000000000000000000000000000000000000000000000000000}{\url{doi: 10.0000/Journal.000000000000000000000000000000000000000000000000000000000000}}}


Result:

It is possible to use the xurl package to break (automatically at arbitrary places) a URL (or similar entry), and the \url command can be used inside the argument that is used to display and hyperlink of the \href. Accordingly, the note field in the original post can be changed to

note = {\href{http://dx.doi.org/10.0000/Journal.000000000000000000000000000000000000000000000000000000000000}
{\url{doi: 10.0000/Journal.000000000000000000000000000000000000000000000000000000000000}}}


With the provided MWE it yields:

There are two approaches you can take here. One is to use \sloppy before the bibliography which will let LaTeX insert wider spaces than normal to allow a break before 10.000/Journaletc You may also want to set \emergencystretch=1em to allow LaTeX to not just dump all the extra spacing on one line.

The other thing you could do is insert \allowbreak in the midst of the digit string to allow LaTeX to do a break in the middle of the digits at the point where you have \allowbreak.

• You can use the suggestion by @Mico combining href and url and loading the xurl package. note = {\href{http://dx.doi.org/10.0000/Journal.000000000000000000000000000000000000000000000000000000000000}{\url{doi: 10.0000/Journal.000000000000000000000000000000000000000000000000000000000000}}} – Guido Oct 22 '20 at 5:37
• @Guido, could you submit it as an answer so that I can accept it? – anecdote Oct 23 '20 at 0:18