TeX - LaTeX Asked by Witiko on April 11, 2021
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}
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.
biblatex
has its own URL setup in biburlsetup
(ll. 285-324 of biblatex.def
in v3.16). The default biburlsetup
contains defUrlBigBreaks{do:do-}%
and so explicitly allows line breaks at hyphens. We can undo that by changing UrlBigBreaks
in apptobiburlsetup
.
documentclass{article}
usepackage{biblatex}
apptobiburlsetup{%
defUrlBigBreaks{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}
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.
Correct answer by moewe on April 11, 2021
You can add do-
to UrlNoBreaks
:
defUrlNoBreaks{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}
addbibresource{main.bib}
defUrlNoBreaks{do-do(do[do{do<}%
begin{document}
lipsum[11]
nocite{*}
printbibliography
end{document}
Answered by Ivan on April 11, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP