Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have some long URLs which doesn't contain special "line break characters" like "-" or "/". How can I automatically break these URLs?

\documentclass{scrreprt}

\usepackage[ngerman]{babel}                    
\usepackage[latin1]{inputenc}                
\usepackage[T1]{fontenc}
\usepackage[backend=biber]{biblatex}
\usepackage{url}
\usepackage{dingbat}  % for \carriagereturn symbol
\makeatletter
\g@addto@macro{\UrlBreaks}{\UrlOrds}
\g@addto@macro{\UrlBreaks}{%
\do\/\do\d%
}
\makeatother

\begin{filecontents}{bachelorarbeit_lit.bib}
@ONLINE{java96,
    author = {{Joe Black}},
    title = {Foobar 1.0},
    year = {1996},
    month = {1},
    url = {http://www.aaa.bb.cccc.dh/uploads/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.pdf},
    urldate = {2011-03-02},
    sortname = {Sun},
    keywords = {www}
}
\end{filecontents}

\bibliography{bachelorarbeit_lit}

\begin{document}
Test \cite{java96}
\printbibliography
\end{document}

edit

I don't know why but it still doesn't work. Is there an option to automatically break long URLs. I don't care where the break is but it should be done automatically. Even if I manually specify the "breaking character" it doesn't work (as the example shows).

share|improve this question
1  
Have you seen tex.stackexchange.com/questions/102152/…? Or tex.stackexchange.com/questions/126702/… Does it help? –  Kurt Sep 20 '13 at 0:43
    
I have played now some time with this problem but the other solutions don't help. –  user4811 Sep 20 '13 at 13:13
add comment

1 Answer

up vote 16 down vote accepted

Hacking \UrlBreaks is not needed for \url inside the bibliography of biblatex. Package biblatex uses \biburlsetup and has already added lots of characters. The breaking at some character classes is controlled by counters. From the documentation of biblatex, "4.10.3 User-definable Lengths and Counters":

biburlnumpenalty: If this counter is set to a value greater than zero, biblatex will permit linebreaks after numbers in all strings formatted with the \url command from the url package. This will affect URLs and DOIs in the bibliography. The breakpoints will be penalized by the value of this counter. If URLs and/or DOIs in the bibliography run into the margin, try setting this counter to a value greater than zero but less than 10000 (you normally want to use a high value like 9000). Setting the counter to zero disables this feature. This is the default setting.

biburlucpenalty: Similar to biburlnumpenalty, except that it will add a breakpoint after all uppercase letters.

biburllcpenalty: Similar to biburlnumpenalty, except that it will add a breakpoint after all lowercase letters.

An example:

\RequirePackage{filecontents}
\begin{filecontents}{bachelorarbeit_lit.bib}
@ONLINE{java96,
    author = {{Joe Black}},
    title = {Foobar 1.0},
    year = {1996},
    month = {1},
    url = {http://www.aaa.bb.cccc.dh/uploads/dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.pdf},
    urldate = {2011-03-02},
    sortname = {Sun},
    keywords = {www}
}
\end{filecontents}

\documentclass{scrreprt}

\usepackage[ngerman]{babel}                    
\usepackage[latin1]{inputenc}                
\usepackage[T1]{fontenc}

\usepackage[backend=biber]{biblatex}
\usepackage{url}

%%% --- The following two lines are what needs to be added --- %%%
\setcounter{biburllcpenalty}{7000}
\setcounter{biburlucpenalty}{8000}

\bibliography{bachelorarbeit_lit}

\begin{document}
Test \cite{java96}
\printbibliography
\end{document}

Result

share|improve this answer
    
Now it works! Thanks Heiko!!! –  user4811 Sep 20 '13 at 17:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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