I am using latex-dvips-ps2pdf steps with -Ppdf option passed to dvips. The following code snippet


\hypersetup{pdfborder={0 0 100}}

\def\emailA{\url{abcdefghi.jklmn.opqrs.tuvwxyz@tuvwxyz.com}\ }
\def\emailB{\url{jklmn.opqrs.tuvwxyz.abcdefghi@tuvwxyz.com}\ }
\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 

produces the output as follows.

enter image description here

Is there any trick to fix it?

  • 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, 2011 at 22:06
  • @Lockstep: OK. Sometimes a bit difficult to know what tags I should you. :-) Jun 14, 2011 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, 2011 at 15:34

8 Answers 8


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.


\hypersetup{pdfborder={0 0 100}}

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

The example:

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


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


The example with \verb+\sloppy+: 

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



Try this.

If you have any questions, please don't hesitate to contact me
at \url{mailto:xport@tex.stackexchange.com}.

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

  • 1
    @xport --- Can you use pdflatex instead? Jun 14, 2011 at 22:36
  • It seems \nolinkurl does the trick without even using breaklines=true. Maybe the latter is default now? Jul 21, 2016 at 6:04
  • 2
    Also, nolinkurl changes the font of the text displayed to the document's monospaced font (at least when using fontspec and XeLaTeX). Jul 21, 2016 at 6:04
  • Saved my life! Many thanks for that simple cool hint.
    – Matthias
    Mar 15, 2017 at 14:47
  • 1
    This doesn't really work (unless you use pdflatex in which case you don't need this at all); see this question. Jul 4, 2017 at 21:25

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:



option anythingbreaks

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

  • 3
    Note that this answer is not a duplicate: it discusses the new anythingbreaks option. Apr 11, 2013 at 7:20
  • Hi, could you update the answer with the correct way to use the option anything breaks?
    – otmezger
    Jul 27, 2014 at 22:24
  • 1
    @otmezger Just use \usepackage[anythingbreaks]{breakurl} in your preamble. That's it.
    – MrD
    Jul 28, 2014 at 9:24
  • Simply including that line throws errors for me: ! Undefined control sequence. <argument> \headerps@ {/burl@stx null def /BU.S { /burl@stx null def }de...l.311 }
    – Andy Ray
    Mar 28, 2017 at 0:30

I found 2 solutions for breaking long URLs.

The first one unfortunately doesn't work with hyperref.


This will break long URLs after hyphens, which is mostly ok. But since hyperrefuses urlsomehow, there's a conflict activating the hyphens-option

! LaTeX Error: Option clash for package url.

If somebody has an explanation (or solution) for me, I'd be glad.

The second solution works fine. I haven't researched it intensely, yet. But it should be a clean solution as only the characterlist for linebreaking is manipulated an neither measures nor mechanisms are influenced. (I'd appreciate it, if someone could verify this.)

%or \usepackage{url}

The last line adds the hyphen to the list of characters after which an URL is allowed to break. You can expand the list by adding "dos" like {\do\a\do\b\do\c} (This would allow URLs to break after a, b, and c, too.)

There's also a list \UrlBigBreaks. But I haven't checked it out, yet.

  • The first solution is also discussed here. The solution is to pass the option to url using PassOptionsToPackage before that package is loaded, which may be before documentclass. Jul 5, 2019 at 14:06
  • This is my preferred option, as it only breaks links on "/" and "-". not in more random places (e.g. "."). Jun 24, 2021 at 14:35

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

  • @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. Jun 20, 2011 at 4:49
  • @Gonzalo: Could you make an example as the answer? I will try it. Jun 21, 2011 at 2:48



Lazy answer, but it's working for me, and I'm new in latex:




  • 1
    This breaks the link! Hence you would be redirected to a different URL...
    – m13r
    May 11, 2016 at 13:28
  • you are right, but i have no other way for my two column paper :/
    – Sergio
    May 18, 2016 at 20:26

You can use the \href function twice (or as many times as you link), both linking to the same URL, but the first with the text you want to appear on the first line, and the second with the text you want to appear on the second line. In other words, you decide where the line break occurs. A bit of a bodge but works well for me:

(\href{Full URL}{\underline{Text up to the end of line 1}} \href{Full URL}{\underline{Text for the start of line 2}})

Package Setup:

\RequirePackage[bookmarks, bookmarksopen=true, plainpages=false, pdfpagelabels, pdfpagelayout=SinglePage, breaklinks = true]{hyperref}

Sample Hyperlink:

\href{https://tex.stackexchange.com/a/576098/147162}{Link to this answer!}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.