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 am using latex-dvips-ps2pdf steps with -Ppdf option passed to dvips. The following code snippet

\documentclass{article}

\usepackage[colorlinks]{hyperref}
\usepackage{breakurl}
\hypersetup{pdfborder={0 0 100}}

\def\emailA{\url{abcdefghi.jklmn.opqrs.tuvwxyz@tuvwxyz.com}\ }
\def\emailB{\url{jklmn.opqrs.tuvwxyz.abcdefghi@tuvwxyz.com}\ }
\begin{document}
\emailA or \emailB or \emailB or \emailA or 
\emailA or \emailB or \emailB or \emailA or 
\emailA or \emailB or \emailB or \emailA or 
\emailA or \emailB or \emailB or \emailA or 
\emailA or \emailB or \emailB or \emailA or 
\emailA or \emailB or \emailB or \emailA or 
\emailA or \emailB or \emailB or \emailA or 
\end{document}

produces the output as follows.

enter image description here

Is there any trick to fix it?

share|improve this question
    
Please don't create new "command" tags like {href} unless absolutely necessary. Also, {hyperlink} should be covered by {hyperref}. Instead, I added {line-breaking} for you. ;-) –  lockstep Jun 14 '11 at 22:06
    
@Lockstep: OK. Sometimes a bit difficult to know what tags I should you. :-) –  xport Jun 14 '11 at 22:10
    
Did you try this with pdfLaTeX: it also fails to break all of the lines 'nicely'. There are cases where it's simply not possible for TeX to break lines automatically. –  Joseph Wright Jun 21 '11 at 15:34

4 Answers 4

up vote 4 down vote accepted

Even with the help of the breakurl package, your example will produce overfull boxes. This is because breakurl will only break urls after one of the following symbols :/.?#&_,;! and before any ocurrence of the symbol %.

To overcome this you have two possibilities: to use \sloppy (which will make the spacing look really awful) or to manually insert some spaces in the appropriate places to help the package find a proper break-point for the urls.

In the following example I show a reduced version of your example with three variants: the first one shows the default output obtained with breakurl; in the second one, I manually inserted some \hspaces, and in the third one I used \sloppy. It's up to you to decide which of the two last approaches looks less ugly and is more practical.

I used draft to see the overfull boxes more clearly. The code must be compiled through latex.

\documentclass[draft,10pt]{article}

\usepackage[colorlinks]{hyperref}
\usepackage{breakurl}
\hypersetup{pdfborder={0 0 100}}

\def\emailA{\url{abcdefghi.jklmn.opqrs.tuvwxyz@tuvwxyz.com}\ }
\def\emailB{\url{jklmn.opqrs.tuvwxyz.abcdefghi@tuvwxyz.com}\ }
\begin{document}

The example:

\emailA or \emailB or \emailB or \emailA or
\emailA or \emailB or \emailB or \emailA or 
\emailA or \emailB or \emailB

\vspace{1cm}

The example with \verb+\hspace+s manually inserted: 

\hspace*{-4pt}\emailA or \emailB or \emailB or \emailA\hspace{3pt} or\hspace{4pt} 
\emailA or \emailB or \emailB or \emailA or 
\emailA or \emailB\hspace{3pt} or\hspace{3pt} \emailB

\vspace{1cm}

The example with \verb+\sloppy+: 

\begingroup
\sloppy
\emailA or \emailB or \emailB or \emailA or
\emailA or \emailB or \emailB or \emailA or 
\emailA or \emailB or \emailB\par
\endgroup

\end{document}

share|improve this answer

Try this.

\documentclass{article}
\usepackage[breaklinks=true]{hyperref}
\begin{document}
If you have any questions, please don't hesitate to contact me
at \url{mailto:xport@tex.stackexchange.com}.
\end{document}

With \href, you need to use \nolinkurl in the second argument.

\href{mailto:xport@tex.stackexchange.com}{\nolinkurl{xport@tex.stackexchange.com}}
share|improve this answer
    
@xport --- Can you use pdflatex instead? –  Ian Thompson Jun 14 '11 at 22:36

Have a look at the breakurl package -- page 1 of the documentation includes the answer to your question.

share|improve this answer
    
@xport: it doesn't work because the package can't find a valid character to break some urls. You can use \sloppy (it will work now but the document will look awful) or simply insert some convenient blank space before the problematic urls. –  Gonzalo Medina Jun 20 '11 at 4:49
    
@Gonzalo: Could you make an example as the answer? I will try it. –  xport Jun 21 '11 at 2:48

I finally found a solution, that might be of interest to all the ones having problems with displaying long URLs in LaTeX: I had a little chat with Vilar (the maintainer of the breakurl-package) and he was able to extend the breaking possibilities of his package they way I suggested.

Therefore the new option anythingbreaks in the newest version does the links look good as they keep in range of the textborder.


See for yourself:

Completely without:

without


Standard behavior:

breakurl


Anythingbreaks:

option anythingbreaks

Look also at my question here: Biblatex: URL-breaking not working in DVI-mode

share|improve this answer
3  
Note that this answer is not a duplicate: it discusses the new anythingbreaks option. –  Charles Stewart Apr 11 '13 at 7:20
    
Hi, could you update the answer with the correct way to use the option anything breaks? –  otmezger Jul 27 at 22:24
1  
@otmezger Just use \usepackage[anythingbreaks]{breakurl} in your preamble. That's it. –  DL6ER 2 days ago

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.