How do I allow long URLs to have line breaks at any point. This is in the bibliography not the main text. I am trying to save space so don't want extra spaces to be added to make it only break at slashes, for example, as it does by default. I am using biblatex+biber.
- 6,785
-
2do you want to allow a linebreak at any symbol/character? – Jul 12 '11 at 11:23
-
2Have you already seen this question and the answers given there? – domwass Jul 12 '11 at 11:24
-
1Yes at any symbol/character. I really just want to wrap very crudely to save maximum space. I don't want it to hyphenate however as that would be confusing. – Simd Jul 12 '11 at 12:07
2 Answers
Answers to the question linked in domwass's comment mention the package url. This package is already loaded by biblatex. It is configured with the command \biburlsetup defined in biblatex.def.
URLs are broken at the set of characters specified in \UrlBreaks, \UrlBigBreaks and \UrlSpecials. \UrlBigBreaks will prevent breaks from occurring between repeating characters (e.g. -- and :: in the code below). \UrlSpecials handles breaks at characters that may not be present in the document font.
Upgrading to the latest version of biblatex should solve your problem as \biburlsetup was expanded in version 1.4c to permit breakpoints at many different characters. For reference here is the definition for \biburlsetup from version 1.7:
\newcounter{biburlnumpenalty}
\newcounter{biburlucpenalty}
\newcounter{biburllcpenalty}
\newcommand*{\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 \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 \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 \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}
Unlike versions 1.4c to 1.6, this new definition no longer allows breakpoints at numbers, uppercase letters and lowercase letters by default. Breaks at these characters can be permitted by setting the penalty counters to a value between 0 and 10000, exclusive. For example:
\setcounter{biburlnumpenalty}{100}
\setcounter{biburlucpenalty}{100}
\setcounter{biburllcpenalty}{100}
The penalties can be reset locally using the command \defcounter from the etoolbox package (also loaded by biblatex). For example:
\defcounter{biburlnumpenalty}{3000}
\defcounter{biburlucpenalty}{6000}
\defcounter{biburllcpenalty}{9000}
To use this new setup with an older version of biblatex, just put the code defining \biburlsetup and its penalty counters in your preamble and replace \newcommand with \renewcommand.
-
2
-
Interesting! Could you explain why you handle digits in this way? – Martin Scharrer Jul 12 '11 at 13:51
-
@Martin The
\UrlSpecialsappears as defined bybiblatex/Philipp Lehman. I am not sure why myself. If you (or anyone else for that matter) can figure it out, please feel free to edit my answer. – Audrey Jul 12 '11 at 14:00 -
-
HI, I tried your solution, but
biblatexwon’t break URLs between two letters e.g.http://www.phidgets.com/docs/Programming_ Resourcesshould be broken between the twomofProgrammingbut it doesn’t work … I copied your code ti my preamble and setup\DeclareFieldFormat{url}{\url{#1}}. – Tobi Nov 29 '12 at 11:09 -
@Tobi Unless you're using a version before 1.7, you only need to reset the break penalties. The code above is just explanatory. To handle the odd overfull box you can reset the penalties locally. – Audrey Nov 29 '12 at 14:36
-
Oh … I read your anser again and saw that you posted the default behavior in 1.7, which I’m using. But I don’t get breakpoints in mid words, though … Shall I post a follow-up question? – Tobi Nov 30 '12 at 13:13
-
@Tobi Sorry - correction: by default breakpoints aren't permitted at letters. You should try setting the biburlucpenalty (uppercase letters) and biburllcpenalty (lowercase letter) penalties. Again you can do this locally or globally. – Audrey Nov 30 '12 at 17:01
-
1Hm … where (and how) do I have to change these values? I tried it via
\biburlsetupand at my preamble with\defcounterand\setcounter– nothing happened … – Tobi Dec 02 '12 at 01:48 -
1@Tobi The documentation is your friend. Don't modify
\biburlsetup. Just add the\setcountercommands to your preamble. You can use\defcounterto reset the penalties locally. See the post I linked earlier for an example. – Audrey Dec 02 '12 at 03:32 -
@Audrey Wouldn't it be nice if it had an index?! Thanks for giving me search terms :-). – cfr Mar 02 '17 at 18:11
Even for website references, my Zotero didn't export a url = ... line for .bib files, but just howpublished = {https://...}. This caused some URLs in the bibliography (I had to use multibib, not bibtex) to cause overful hboxes, and the URLs shoot out of the document without a line break.
Apparently, behind the hood, there was no \url, but (I think?) a \href from the hyperref package, which has different behavior.
Out of the MANY options I tried, I ended up manually replacing the howpublished = {https://...} with a howpublished = {\url{https://...}} for the broken links. The URLs might look ugly then, this can be fixed with \urlstyle{rm} after \usepackage[hyphens]{url}.
- 121