# Forbid BibLaTeX to break URLs at hyphens

By default, BibLaTeX will happily break lines at hyphens in URLs:

\documentclass{article}
\begin{filecontents}{main.bib}
@online{entry,
title = {Title},
subtitle = {Subtitle},
author = {Doe, John},
url = {http://some-quite-long-url-that-contains-hyphens},
}
\end{filecontents}
\usepackage{biblatex}
\begin{document}
\nocite{*}
\printbibliography
\end{document}


This can easily lead to confusion: was the hyphen added as a part of hyphenation, or is it a meaningful part of the URL? Therefore, I would like to forbid the hyphenation of URLs at hyphens.

BibLaTeX uses the url package, which does not break URLs at hyphens by default, and I see no mention about this behavior in the BibLaTeX documentation.

• if you forbid the break there, the url can't break at all (or only after the //) and this will lead to bad spacing. Imho in the bibliography it is better to accept more break places, even if this leads to slightly confusing urls. – Ulrike Fischer Mar 19 at 11:44
• @UlrikeFischer In this MWE, I agree. However, there is often plenty / in the URLs and DOIs, which may be considered better line break points. – Witiko Mar 19 at 17:12

biblatex has its own URL setup in \biburlsetup (ll. 285-324 of biblatex.def in v3.16). The default \biburlsetup contains \def\UrlBigBreaks{\do\:\do\-}% and so explicitly allows line breaks at hyphens. We can undo that by changing \UrlBigBreaks in \appto\biburlsetup.

\documentclass{article}

\usepackage{biblatex}

\appto\biburlsetup{%
\def\UrlBigBreaks{\do\:}}

\begin{filecontents}{\jobname.bib}
@online{entry,
title    = {Title},
subtitle = {Subtitle},
author   = {Doe, John},
url      = {http://some-quite-long-url-that-contains-hyphens},
}
\end{filecontents}
\begin{document}
\nocite{*}
\printbibliography
\end{document}


Of course not allowing to break URLs at hyphens can make many 'modern' URLs extremely hard to break at all. If a URL is typeset in a different font than the main text, most readers are probably warned that any hyphens appearing in the URL are real and not caused by hyphenation.

You can add \do\- to \UrlNoBreaks:

\def\UrlNoBreaks{\do\-\do\(\do\[\do\{\do\<}%


But as you can see from the example below in this way the url can not break and the result is ugly:

MWE

\documentclass{article}
\begin{filecontents}[overwrite]{main.bib}
@online{entry,
title = {Title},
subtitle = {Subtitle},
author = {Doe, John},
url = {http://some-quite-long-url-that-contains-hyphens},
}
\end{filecontents}
\usepackage{lipsum}
\usepackage{biblatex}