[Tex/LaTex] linebreak in long URL? Breakurl won’t break it

hyperrefline-breaking

There are several questions on this site (for example here and here) where people are struggling with overfill hboxes when making clickable URLs. I have read and tried the answers there and none of them seem to work for me, so I thought I would ask a new question.

Here's a minimal example of my problem:

\documentclass[english]{amsart}
\usepackage[bookmarksopen,bookmarksdepth=2,breaklinks=true]{hyperref}
\usepackage[anythingbreaks]{breakurl}
\begin{document}
Here's a longish sentence so I can just keep track of where the
end of the page is as far as normal line breaks are concerned.

However, Blah de blah de blah de blah
blah ~\href{https://blahblaaaaaaaaaaaaaaa.aaaaaaaaa.com/xxxx/xx/xx/blaaah-bl-blaaaah-bla/}{https://blahblaaaaaaaaaaaaaaa.aaaaaaaaa.com/xxxx/xx/xx/blaaah-bl-blaaaah-bla/} an argument which shows that\ldots
\end{document}

I have a sentence with pretty much this syntax/length in a paper I'm writing (including the URL which is the same length as the one I'm quoting and has slashes, hyphens, full stops in the same place). When I run the above through pdflatex I get an overfill hbox and this:

enter image description here

I don't care where that URL breaks, but I am reluctant to just break it myself because this paper has been accepted by a journal and they might well play with the margins etc and end up re-breaking something if I fix it in an ad hoc manner.

I had thought that breakurl, especially with its relatively new anythingbreaks option, would just break the URL to fit it on the page. As you can see, it hasn't done so.

Here are the things I've tried:

  • Adding \usepackage[hyphens]{url} in various places.

  • Discovering that breakurl will only break URLs after one of :/.?#&_,;! (but there's a . in the URL (the first one) after which it would be a perfect place to break the URL)

  • Using \sloppy (changed nothing)

  • \def\UrlBreaks{\do\/\do-\do.} (changed nothing)

I guess what I want in this case is the break after blahblaaaaaaaaaaaaaaa. I do not understand why I cannot persuade the URL to break here. Can anyone help?

To make matters worse, when my coauthor uploaded the paper to ArXiv, ArXiv choked on the TeX, possibly because it didn't have the most recent breakurl so choked on [anythingbreaks], and possibly because it was complaining about an options clash with hyperref. However this problem might go away once I've broken this URL.

Best Answer

EDIT2:

According to the hyperref-manual, breaklinks is automatically set by the driver. A manual override as tried results in the behaviour as experienced by QO.

If you don't mask the URL in

\href{long URL goes here}{here goes a masking label}

then you could simply use (using \usepackage{hyperref} or \usepackage[hyphens]{url})

\url{long URL}

with the result of having a correctly typeset URL.

Code as follows. See result in 1:

\documentclass[english]{amsart}
\usepackage[
bookmarksopen,
bookmarksdepth=2,
breaklinks=true
]{hyperref}

\begin{document}
Here's a longish sentence so I can just keep track of where the
end of the page is as far as normal line breaks are concerned.

However, Blah de blah de blah de blah
blah ~\url{https://blahblaaaaaaaaaaaaaaa.aaaaaaaaa.com/xxxx/xx/xx/blaaah-bl-blaaaah-bla/} an argument which shows that\ldots
\end{document}

Result of above Code

EDIT:

Same code with some improvements. See result in 2:

\documentclass[english]{amsart}
\usepackage{xcolor}
\usepackage[
bookmarksopen,
bookmarksdepth=2,
%breaklinks=true
colorlinks=true,
urlcolor=blue]{hyperref}

\begin{document}

%using \url{URL}
However, Blah de blah de blah de blah
blah \url{https://blahblaaaaaaaaaaaaaaa.aaaaaaaaa.com/xxxx/xx/xx/blaaah-bl-blaaaah-bla/} an argument which shows that\ldots

%using \href{URL}{text}
\href{https://blahblaaaaaaaaaaaaaaa.aaaaaaaaa.com/xxxx/xx/xx/blaaah-bl-blaaaah-bla/}{here is link to web}

\end{document}

Result of improved code