LaTeX forum ⇒ Text FormattingLine breaks in URLs

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
tuxx
Posts: 3
Joined: Tue Feb 17, 2009 12:18 pm

Line breaks in URLs

Postby tuxx » Tue Feb 17, 2009 12:23 pm

Hi,

I have the following problem:

\usepackage{url}
\usepackage{hyperref}
...
\url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}

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.

Link:
BBcode:
HTML:
Hide post links
Show post links

Rasmus
Posts: 2
Joined: Tue Feb 17, 2009 6:11 pm

Postby Rasmus » Tue Feb 17, 2009 6:39 pm

You can make url less restrictive. For example using the option hypens:
  1. \documentclass{minimal}
  2. \usepackage[hyphens]{url}
  3. \usepackage{hyperref}
  4. \begin{document}
  5. This is some filler text \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  6. \end{document}

Link:
BBcode:
HTML:
Hide post links
Show post links

daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Postby daleif » Tue Feb 17, 2009 8:10 pm

tuxx wrote:Hi,

I have the following problem:

\usepackage{url}
\usepackage{hyperref}
...
\url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}

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

Link:
BBcode:
HTML:
Hide post links
Show post links

tuxx
Posts: 3
Joined: Tue Feb 17, 2009 12:18 pm

Postby tuxx » Wed Feb 18, 2009 3:46 pm

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

  1. \documentclass[10pt,a4paper]{article}
  2. \usepackage[hyphens]{url}
  3. \usepackage{hyperref}
  4.  
  5. \setlength{\parindent}{0em}
  6. \setlength{\parskip}{1em}
  7.  
  8. \begin{document}
  9.  
  10. 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.
  11. This is some filler text \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  12.  
  13. a \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  14.  
  15. aa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  16.  
  17. aaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  18.  
  19. aaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  20.  
  21. aaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  22.  
  23. aaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  24.  
  25. aaaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  26.  
  27. aaaaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  28.  
  29. aaaaaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  30.  
  31. aaaaaaaaaa \url{http://www.coreavc.com/index.php?option=com_content&task=view&id=27&Itemid=1}
  32.  
  33. \end{document}

Link:
BBcode:
HTML:
Hide post links
Show post links

daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Postby daleif » Wed Feb 18, 2009 3:56 pm

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.

Link:
BBcode:
HTML:
Hide post links
Show post links

tuxx
Posts: 3
Joined: Tue Feb 17, 2009 12:18 pm

Postby tuxx » Wed Feb 18, 2009 4:14 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
jiapei100
Posts: 28
Joined: Sat Jan 12, 2008 7:23 pm
Location: England
Contact:

Postby jiapei100 » Mon May 04, 2009 5:17 am

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".

So, every time I got "Error 404: File Not Found".
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

Link:
BBcode:
HTML:
Hide post links
Show post links

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Postby phi » Mon May 04, 2009 9:21 am

The url package sets URLs in math mode, so any spaces are actually ignored. So the code
  1. \documentclass{minimal}
  2. \usepackage[hyphens]{url}
  3. \begin{document}
  4. \url{http://www.visionopen.com/products/JP_ASMAAMBuilding_media/
  5. JP_ASMAAMBuilding.avi}
  6. \end{document}
doesn't produce additional spaces in the URL.

Furthermore, the url package doesn't create hyperlinks, only hyperref does. The corresponding code
  1. \documentclass{minimal}
  2. \usepackage[breaklinks]{hyperref}
  3. \begin{document}
  4. \url{http://www.visionopen.com/products/JP_ASMAAMBuilding_media/
  5. JP_ASMAAMBuilding.avi}
  6. \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.

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
jiapei100
Posts: 28
Joined: Sat Jan 12, 2008 7:23 pm
Location: England
Contact:

Postby jiapei100 » Mon May 04, 2009 2:05 pm

Thank you very much for your prompt reply.

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.

Can you please help to find out where I should change in the settings?

Thanks.

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

Link:
BBcode:
HTML:
Hide post links
Show post links

daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Postby daleif » Mon May 04, 2009 2:44 pm

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.

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 2 guests