Url Linebreaks with hyphens

In LaTeX, urls are best embedded in a document, using the url package.
This package is supposed to take care of the proper formatting of urls which are inserted using the \url{...} command.
The package should also break urls properly if they exceed the length of a line. Unfortunately, this does not work in all cases.

In my case (using pdflatex), I tried to embed the url http://www.uni-bamberg.de/en/pi/bereich/research/software-projects/pattern-based-analysis-of-orchestration-languages/ which is obviously quite long and does not fit into a single line.
The problem here is that the url package does not break hyphens by default. This can be enabled by loading the package with the hyphens option.
For some reason, this did not yet fix my problem.

After a while of google-ing and reading, I found a way to fix this, although this means to modify the line breaking mechanism of TeX itself.
The \sloppy command tells TeX to break lines less often at the cost of more space between single words in a line. My default configuration is \fussy which breaks lines more often, but minimizes the space between single words.
So my solution of line breaking for long urls with hyphens looks as follows:


Put in words, I change the line breaking mechanism just before embedding the large url and then change it back to the default. This is not a beatiful solution at all, but at least a working and quick one.

Edit: In the end, I also shortend the url. So for anyone who is interested, you can find it at http://www.uni-bamberg.de/en/pi/bereich/research/software-projects/pattern-based/ The above method works nevertheless.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s