2

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}
\addbibresource{main.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

result of typesetting the above code with pdfLaTeX

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.

2
  • 1
    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
1

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}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

No line break in long URL.

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.

1

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:

enter image description here

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}
\addbibresource{main.bib}

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

\begin{document}
\lipsum[11]
 \nocite{*}
 \printbibliography
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.