### Who is online

In total there are 10 users online :: 1 registered, 0 hidden and 9 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: Yahoo [Bot] and 9 guests

## Line breaks in URLs

Add tags Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)

### Line breaks in URLs

Hi,

I have the following problem:

\usepackage{url}
\usepackage{hyperref}
...

The thing is that the URL is too long and it's not broken into multiple lines. From what I've read, it seems that the url package should take care of this, but it doesn't. Do you know any way to force the splitting ? Thank you.
tuxx

Posts: 3
Joined: Tue Feb 17th, 2009

### Re: Line breaks in URLs

You can make url less restrictive. For example using the option hypens:
Code: Select all  •  Open in writeLaTeX
\documentclass{minimal}\usepackage[hyphens]{url}\usepackage{hyperref}\begin{document}This is some filler text \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}\end{document}
Rasmus

Posts: 2
Joined: Tue Feb 17th, 2009

### Re: Line breaks in URLs

tuxx wrote:Hi,

I have the following problem:

\usepackage{url}
\usepackage{hyperref}
...

The thing is that the URL is too long and it's not broken into multiple lines. From what I've read, it seems that the url package should take care of this, but it doesn't. Do you know any way to force the splitting ? Thank you.

how are you compiling? latex + dvips + ps2pdf does not automatically break URLs under hyperref, whereas pdflatex does. whith latex + dvips you also need breakurl
daleif

Posts: 199
Joined: Wed Nov 19th, 2008

### Re: Line breaks in URLs

I'm compiling with pdflatex. Thanks Rasmus, but the solution doesn't seem to work:

Code: Select all  •  Open in writeLaTeX
\documentclass[10pt,a4paper]{article}\usepackage[hyphens]{url}\usepackage{hyperref}\setlength{\parindent}{0em}\setlength{\parskip}{1em} \begin{document}The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.This is some filler text \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}a \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}aa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}aaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}aaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}aaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}aaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}aaaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}aaaaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}aaaaaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}aaaaaaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}\end{document}
tuxx

Posts: 3
Joined: Tue Feb 17th, 2009

### Re: Line breaks in URLs

breaks fine for me, but some of the text goes into the right margin because TeX is trying to maintain a strait right edge, and thus chooses these breaks to be better than stretching the word space too much.

This can be seen if you add \sloppy at the start of the codument.
daleif

Posts: 199
Joined: Wed Nov 19th, 2008

### Re: Line breaks in URLs

Thanks a lot, that \sloppy did the thing along with the hyphens option.
tuxx

Posts: 3
Joined: Tue Feb 17th, 2009

### Re: Line breaks in URLs

No, this doesn't work for me at all.

I used

1)
\usepackage[hyphens]{url}

2)
\begin{document}
\sloppy

But, in my latex file, I had a \url

\url{http://www.visionopen.com/products/JP_ASMAAMBuilding_media/
JP_ASMAAMBuilding.avi}

Since the url is too long that I can't put such a url in a single row of latex editor Kile. There is a "return carriage" before "JP_ASMAAMBuilding.avi".

Therefore, whenever after I built the .pdf file, I can't manage to link to the url I want, because there is a space just before "JP_ASMAAMBuilding.avi".

which actually means

"http://www.visionopen.com/products/JP_ASMAAMBuilding_media/ JP_ASMAAMBuilding.avi" is not a file.

My question is how I can manage to remove the space before "JP_ASMAAMBuilding.avi" so that the link address is really an available one?

Urgent!!!

Rgds
JIA
Welcome to Vision Open
http://www.visionopen.com

jiapei100

Posts: 28
Joined: Sat Jan 12th, 2008
Location: England

### Re: Line breaks in URLs

The url package sets URLs in math mode, so any spaces are actually ignored. So the code
Code: Select all  •  Open in writeLaTeX
\documentclass{minimal}\usepackage[hyphens]{url}\begin{document}\url{http://www.visionopen.com/products/JP_ASMAAMBuilding_media/JP_ASMAAMBuilding.avi}\end{document}
doesn't produce additional spaces in the URL.

Furthermore, the url package doesn't create hyperlinks, only hyperref does. The corresponding code
Code: Select all  •  Open in writeLaTeX
\documentclass{minimal}\usepackage[breaklinks]{hyperref}\begin{document}\url{http://www.visionopen.com/products/JP_ASMAAMBuilding_media/JP_ASMAAMBuilding.avi}\end{document}
indeed exhibits the described behavior. Solution: Configure your editor so that the line break is not inserted (this behavior is clearly wrong, and would even be so in normal text mode). In the unlikely case that this is impossible add a comment sign right after the slash.
phi

Posts: 578
Joined: Tue Oct 21st, 2008

### Re: Line breaks in URLs

I am using Kile under Linux. So, can you please tell me where I can specify "no space at the end of line" in Kile editor?

I tried all items under
Kile->Settings->Configure Kile,
but I can't find anything related to how to solve the problem encountering.

Thanks.

Best Regards
JIA
Welcome to Vision Open
http://www.visionopen.com

jiapei100

Posts: 28
Joined: Sat Jan 12th, 2008
Location: England

### Re: Line breaks in URLs

Static wordwrap be the problem.

Settings -> editor -> editing

at least it didn't work well in the (old) version I tested with the URL you specified.
daleif

Posts: 199
Joined: Wed Nov 19th, 2008

Next