How to allow line break in a long hyperlink in a PDF compiled by latex-dvips-ps2pdf?
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:[email protected]}.
\end{document}
With \href
, you need to use \nolinkurl
in the second argument.
\href{mailto:[email protected]}{\nolinkurl{[email protected]}}
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{[email protected]}\ }
\def\emailB{\url{[email protected]}\ }
\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}
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:
Standard behavior:
Anythingbreaks:
Look also at my question here: Biblatex: URL-breaking not working in DVI-mode