# BibLaTeX long URL extending into border despite using biburllcpenalty

MWE:

### test.tex:

% !TeX program = xelatex
\documentclass[paper=A4,fontsize=12pt]{scrartcl}
\usepackage[left=3cm, right=3cm, bottom=3cm, top=3cm]{geometry}
\usepackage{fontspec}
\usepackage[backend=biber,style=authoryear,citestyle=authoryear]{biblatex}
\DeclareNameAlias{sortname}{last-first}
\DeclareNameAlias{default}{last-first}
\setcounter{biburllcpenalty}{7000}
\setcounter{biburlucpenalty}{9999}
\begin{document}
\cite{Test.2018}
\printbibliography
\end{document}


### resources.bib:

@misc{Test.2018,
author = {{testauthor test author testauthor}},
year= {2018},
title = {{testfile test file testfile}},
url = {http://abcdefghijklmnopqrstuvwxy.com/phrrFK5dS1ztTjiaCmveRARXpGBtV01U%20B93FcrxkOVhj2CceIguNuUPpwDaUD4GjTTWh9cL30D6rLgWxapYlhegDXQGFlE0hao7B2YS227ca%20keoWHWNmQVKVcNOUFxfsCp0SwCElfTVtpMv6DKqiSwhWgO2zrHvstd4UNBo99UQBSCTkzL7lD2UyRLTRy6xXdJ}
}


Here the URL does not break properly due to the fontspec package changing the parindent. How can I fix this?

\begingroup
\sloppy
\printbibliography
\endgroup


This makes the URL look extremely ugly with the first line not even justified. It is just this one weird character extending into the border. I do not want to use any weird workarounds like using the url package and changing the bibliography when BibLaTeX supports URLs natively with Biber.

• Young Un Thank you for helping keep things into the QA structure in the other question. It definitely works better this way. If I may, I have another suggestion. How about you use in your question the actual URL that's giving you trouble? If you provide us with an arbitrarily long made up URL, the only general solution may be to use something of the kind of \sloppy. But usually real URL are less badly behaved (even if nasty enough!), so the real case might get you a better solution. – gusbrs Dec 16 '18 at 18:29
• You could also use \setcounter{biburlnumpenalty}{9900} (or some other value), to also allow breakpoints after numbers. – Skillmon Dec 16 '18 at 18:33
• Thanks for staying with me! Actually the real url is of a similar length and also composed of a similar length of random characters (or base64 strings) after the tld. This is what confuses me. The url is literally a string of random characters and latex decides not to break at one random point that is at the end of the regular line but instead after the next character. I tried setting biburlnumpenalty, it did not have an impact either. – pomeloy Dec 16 '18 at 18:36
• Mmh, In this case, let's see what folks have to say. – gusbrs Dec 16 '18 at 18:39
• As to your comment "I do not want to use any weird workarounds like using the url package and changing the bibliography when biblatex supports urls natively with biber." Actually biblatex loads the url package and it is url that provides biblatex's support for urls. So, you might as well use its options, if they do get things better. – gusbrs Dec 16 '18 at 18:47

You could insert a bit stretchable space:

\documentclass[paper=A4,fontsize=12pt]{scrartcl}
\usepackage[left=3cm, right=3cm, bottom=3cm, top=3cm]{geometry}
\usepackage{fontspec}

\usepackage[backend=biber,style=authoryear,citestyle=authoryear]{biblatex}
\DeclareNameAlias{sortname}{last-first}
\DeclareNameAlias{default}{last-first}
\setcounter{biburllcpenalty}{100}
\setcounter{biburlucpenalty}{100}
\setcounter{biburlnumpenalty}{100}

\renewcommand*{\biburlsetup}{%
\Urlmuskip=0mu plus 3mu\relax
\mathchardef\UrlBigBreakPenalty=100\relax
\mathchardef\UrlBreakPenalty=200\relax
\def\UrlBigBreaks{\do\:\do\-}%
\def\UrlBreaks{%
\do\.\do\@\do\/\do\\\do\!\do\_\do\|\do\;\do\>\do\]\do\)\do\}%
\do\,\do\?\do\'\do\+\do\=\do\#\do\\$\do\&\do\*\do\^\do\"}%
\ifnumgreater{\value{biburlnumpenalty}}{0}
{\def\do##1{\appto\UrlSpecials{\do##1{\mathchar##1 \mskip 0mu plus 1mu\penalty\value{biburlnumpenalty}}}}%
\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\0}
{}%
\ifnumgreater{\value{biburlucpenalty}}{0}
{\def\do##1{\appto\UrlSpecials{\do##1{\mathchar##1 \mskip 0mu plus 1mu\penalty\value{biburlucpenalty}}}}%
\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}
{}%
\ifnumgreater{\value{biburllcpenalty}}{0}
{\def\do##1{\appto\UrlSpecials{\do##1{\mathchar##1 \mskip 0mu plus 1mu\penalty\value{biburllcpenalty}}}}%
\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}
{}%
\let\do=\noexpand}

\begin{document}

\cite{Test.2018}
\printbibliography
\end{document}


• +1 I played with this definition quite a lot, to no avail. But why does placing the glue inside \UrlSpecials differs from setting a larger glue in \Urlmuskip? – gusbrs Dec 16 '18 at 20:36
• \Urlmuskip has an effect only at the dot and the slash. It doesn't affect the problematic line. – Ulrike Fischer Dec 16 '18 at 20:39
• Ah! so that's why I had to go up to 10mu just to get a lousy result... – gusbrs Dec 16 '18 at 20:41

try

\usepackage[style=authoryear,citestyle=authoryear]{biblatex}
\usepackage{xurl}
`

• Tried, did not work at all. The url now overshoots the page by about 10 cm. – pomeloy Dec 16 '18 at 19:25
• see edited answer – user2478 Dec 16 '18 at 19:51
• Is using a whole different mono font the only way to fix one single linebreak? – pomeloy Dec 16 '18 at 19:52
• this font is only an example! – user2478 Dec 16 '18 at 19:54
• I'm sorry, I can not follow. Your example literally changes the font and my problem is about an url not breaking the way I want it to. – pomeloy Dec 16 '18 at 21:42