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
\usepackage[colorlinks=true,breaklinks]{hyperref}
\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)
\sloppy
I use the following commands in place of the enumeration environment
\sloppy
\emergencystretch=1em
\begin{enumerate}
\item \publication{test}
\end{enumerate}
You can see that it does solve the problem of line breaking, but more like in a way of Microsoft Word rather than LaTeX.
- 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.
Add xurl package
\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: