What I am about to ask has already been asked many times, but nothing seems to work for me so far. Basically I am having troubles in getting urls hyphenated correctly in the bibliography.
I modified the command \UrlBreaks
so that it allows hyphenation everywhere, but this seems to be ignored in the bibliography, while in the rest of the document it does work.
Here is a MWE:
% !TEX encoding = UTF-8
% !TEX program = xelatex
\documentclass[12pt,english,a4paper]{article}%
\usepackage[backend=bibtex,defernumbers=true,sorting=nty]{biblatex}%
\usepackage[breaklinks,plainpages=false]{hyperref}%
\def\UrlBreaks{\do\/\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z\do0\do1\do2\do3\do4\do5\do6\do7\do8\do9\do=\do/\do.\do:}
\addbibresource{Biblio.bib}
\begin{document}
See \cite{citation} for further details or visit \url{http://www.joifewoirjecpwoirjcpewrijcpenwrjcpnewrjicpnwerjincpejricpejripcne.com}.
\printbibliography
\end{document}
and the references are in the file Biblio.bib as follows
@book{citation,
author = {Doe, John},
title = {The Book},
url = {http://www.joifewoirjecpwoirjcpewrijcpenwrjcpnewrjicpnwerjincpejricpejripcne.com}
}
Compiling with xelatex
(or pdflatex
) and bibtex
results in the following output:
A curiosity (hope it helps in finding the bug): the image above is what comes out compiling with xelatex
; compiling with pdflatex
gives the same output, except for the cyan countour line of the link which, ironically, gets hyphenated:
Using \sloppy
does something better, but still doesn't make the links hyphenate where I want, i.e. anywhere:
As you may imagine, \raggedright
doesn't solve the issue either.
What I am looking for is some code that allows a good hyphenation of the urls in the bibliography with these constraints (I don't know if they are relevant):
- it has to work with
xelatex
andbibtex
(backend=biber
option tobiblatex
doesn't work for me somehow) - package
polyglossia
must not be required, rather it has to work withbabel
- compatible with package
hyperref
- compatible with
book
document class
Best Answer
biblatex
has a number of counters which when set to non-zero positive values less than10000
allow breaks in urls in the bibliography. The specific counters arefor breaks after numbers, uppercase letters and lowercase letters, respectively. In your case it suffices to set the lowercase penalty to
9000
; lower values encourage breaks more (or rather discourage them less). The setting is done value via\setcounter
:When choosing values for these penalties it is useful to note that
biblatex
's defaults arefor breaks after
:
and-
, andfor breaks after most punctuation characters. You want to set the other penalties significantly higher, so that breaks after numbers and letters are of a lower prioriy than those after punctuation marks. If you need to change the two
\Url...BreakPenalty
s above then it is via the unusual syntax of