4

This is a slightly odd one. I've been trying to get \url{} blocks to wrap really long URLs, and the only thing that seemed to work was to renew the \UrlBreaks command to allow breaking on practically all characters.

However, whilst that prevents the long URL from overlapping the page margins, it seems to still push characters into the marginal notes spaces (defined by \marginparsep and \marginparwidth).

The following document shows the problem:

\RequirePackage[hyphens]{url}
\documentclass[12pt]{article}

\usepackage[hyphens]{url}
\PassOptionsToPackage{hyphens}{url}
\usepackage[colorlinks=true, urlcolor=blue]{hyperref}
\usepackage[margin=1cm, bottom=3.5cm, top=3.5cm, head=2cm]{geometry}
\usepackage{showframe}
\usepackage{blindtext}

\setlength\parindent{0pt}

\let\origUrlBreaks\UrlBreaks
\renewcommand*{\UrlBreaks}{\origUrlBreaks\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X\do\Y\do\Z\do\0\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\.\do\/\do\-\do\_\do\?\do\&\do\=}

\begin{document}

\blindtext

\url{http://really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-really-long-url.com}
\end{document}

When I compile it, half of the 'y' in really, and the entire '-' get pushed into the \marginparsep area. However, this does not seem to happen for blocks of regular text. See here:

enter image description here

Does anyone know why this happens, and what to do to fix it?

9

There is no flexibility in your lines so TeX has nowhere to break.

Add

\Urlmuskip = 0mu plus 1mu

enter image description here

  • That was it. Cheers! – Rsaesha Apr 10 '13 at 17:00

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.