9

First I should say that I don't have much experience with LaTeX.

I'm using BibLaTeX and Biber.

My Problem: I have a (justified) bibliography with long URL's containing long words. BibLaTeX makes a linebreak at a place with a slash. But I want to make that linebreak in the following word.

In the minimal example: I want to do the linebreak at: Markt-beobachtung.

The aim is that in the second line there aren't that big spaces between the letters, words, slashes. And that the second line doesn't start with //.

I'm trying to do this for 3 hours now, so I really appreciate your help.

Here is the .tex file.

\documentclass[oneside]{scrbook}
\usepackage[backend=biber,style=alphabetic]{biblatex}
\usepackage[ngerman]{babel}
\bibliography{test_bib.bib}

\begin{document}
\cite{bundesnetzagentur}
\printbibliography
\end{document}

And that's the test_bib.bib:

@ONLINE{bundesnetzagentur,
author = {Bundesnetzagentur},
title = {Teilnehmerentwicklung im Mobilfunk},
year = {2012},
url = {http://www.bundesnetzagentur.de/DE/Sachgebiete/Telekommunikation/Marktbeobachtung/Mobilfunkteilnehmer/Mobilfunkteilnehmer_node.html },
hyphenation=ngerman
}
Vlad
  • 91
  • 1
  • 2

2 Answers2

10

The package biblatex loads the package url. The list of characters that allow line-breaks is given by \UrlBreaks and \UrlBigBreaks, which have the format \do\c for each character c. For more information read the documentation.

The default setting of \UrlBreaks is

\def\UrlBreaks{\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\;\do\>\do\]%
  \do\)\do\,\do\?\do\'\do+\do\=\do\#}%
\def\UrlBigBreaks{\do\:\do@url@hyp}%

To allow more break points you can add

\g@addto@macro{\UrlBreaks}{\UrlOrds}

for ordinary symbols and you can do

\g@addto@macro{\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}

for breakpoints after letters.

In the same way you can setup the command \UrlNoBreaks to define symbols/letters where no linebreaks are allowed. The default setting is:

\def\UrlNoBreaks{\do\(\do\[\do\{\do\<}%

The commands using the special symbol @. So you need \makeatletter/\makeatother. Please refer the question What do \makeatletter and \makeatother do? for more information.

Marco Daniel
  • 95,681
  • 2
    OK with that commands I can set the characters which allow a linebreak. But I want to set the linebreak manually. I tried your suggestion. But it makes a linebreak at a bad place. It's doing: Ma \linebreak rktbeobachtung – Vlad Mar 16 '13 at 08:13
  • 1
    Is there some way to have this only operate on one url? I tried giving the default \def\UrlBreaks, again, but it had no effect. – Faheem Mitha Jun 16 '15 at 06:16
  • 2
    You can add to the bib entry you are interested in modifying the field Execute = {\def\UrlBreaks{}} or whatever modification to the url package you need. – SiliconValley Aug 25 '15 at 11:17
0

It's not great, but if you want to do it manually, then you can do it manually:

@online{bundesnetzagentur,
author = {Bundesnetzagentur},
title = {Teilnehmerentwicklung im Mobilfunk},
year = "2012",
addendum = "\texttt{\href{http://www.bundesnetzagentur.de/DE/Sachgebiete/Telekommunikation/Marktbeobachtung/Mobilfunkteilnehmer/Mobilfunkteilnehmer_node.html}{http://www.bundesnetzagentur.de/DE/Sachgebiete/Telekommunikation/Markt\\beobachtung/Mobilfunkteilnehmer/Mobilfunkteilnehmer\_node.html}}",
hyphenation=ngerman
}

Note that:

  1. It requires loading hyperref package in the preamble of the document.
  2. In the text part of href, _ needs to be replaced by \_ to avoid errors.

If you don't necessarily want a hyperlink, you can remove \href and the first group in curly brackets, and then you don't need to load the hyperref package.

Something similar can be done with doi addresses too, for example:

addendum = "doi:\href{https://doi.org/10.1023/B:MOON.0000031922.78588.6d}{10.1023/B:MOON.0000031922.785\\88.6d}"
Alex867
  • 57
  • It is easier to just load xurl and just USE \url{URL}. In xurl the url is alloto line break at any char. – daleif Apr 05 '21 at 16:35