Consider the document
\documentclass{article}
\usepackage{lipsum}
\usepackage{hyperref}
\begin{document}
\edef\l{Lorem,ipsum,dolor,sit,amet,,
consectetur,adipiscing,elit,,sed,do,
eiusmod,tempor,incididunt,ut,labore,et,dolore,magna,aliqua. ,,Ut,
enim,ad,minim,veniam,,quis,nostrud,exercitation,ullamco,laboris,
nisi,ut,aliquip,ex,ea,commodo,consequat. ,,Duis,aute,irure,
dolor,in,reprehenderit,in,voluptate,velit,esse,cillum,dolore,eu,
fugiat,nulla,pariatur. ,,Excepteur,
sint,occaecat,cupidatat,non,proident,,sunt,in,culpa,qui,officia,
deserunt,mollit,anim,id,est,laborum.}
\url{\l}
\url{\l}
\url{\l}
\url{\l}
\url{\l}
\url{\l}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
\url{\l}
\end{document}
It produces a url that breaks across the page, causing the issues described in Hyperref Link Spans a Pagebreak, Looks Ugly. However, if I put the link in an \mbox
as suggested by https://tex.stackexchange.com/a/182769/2066, then the url runs off the right side of the page. I can set \interlinepenalty 10000
as suggested by https://tex.stackexchange.com/a/21985/2066, but that's not ideal for long paragraphs as it results in not breaking that paragraph at all. I can insert \widowpenalties 7 10000 10000 10000 10000 10000 10000 0
which does what I want here, but that requires knowing how many lines the link spans and where it is in the paragraph, etc. Is there a better way, or at least a way to automate the calculation of the arguments to \windowpenalties
and hide it behind a command? (And is there a way to support multiple non-page-breakable links in the same paragraph? (It would be nice for this to be an option of the hyperref
package...))
Edit: Since it seems like it might be relevant, I need a solution that works with PDFs generated by LuaLaTeX and not just pdflatex.
sloppypar
with the urls in\mbox
es, perhaps with a bit of rewriting. (But, of course, that's not automatic.)