# Making url package customized break settings apply only to specific urls

I have an huge url consisting mostly of letters. I found Marco's answer to a url breaking question, and using

\g@addto@macro{\UrlBreaks}{\UrlOrds}


and

\g@addto@macro{\UrlBreaks}{%
\do\/\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}


in the preamble allowed my url to break at a letter. However, now all the urls split on a letter. So, the question is, can I selectively enable it for certain urls?

I tried setting the default \def\UrlBreaks after the url in question, but it had no effect.

MWE follows. How can I selectively split the first url, but not the second? The current version splits both.

\documentclass[12pt]{article}
\usepackage[hyphens]{url}
\usepackage[T1]{fontenc}
\usepackage{fouriernc}
\makeatletter
\do\/\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}
\makeatother
\begin{document}

This is a \url{http://reallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongurl} which
\LaTeX\ will be unhappy about. So, how can we split this in the best way?

Here is another one which I don't want to split,
\url{http://notquitesolongastheotheroneurl}.

\end{document}

• you could just set it back again afterwards or just set it locally for the one URL you want to change (ie don't use \g@addto@macro which as the g indicates is a global definition). You've been here long enough to know you don't need to ask the implied question in the last line:-) Jun 16 '15 at 8:21
• @DavidCarlisle I've added a MWE. "just set it locally for the one URL" would work for me. How do I do that? Jun 17 '15 at 9:28
• Put it in a group, {\def\UrlBreaks{...}\url{someUrl}} Jun 17 '15 at 9:38

\documentclass[12pt]{article}
\usepackage[hyphens]{url}
\usepackage[T1]{fontenc}
\usepackage{fouriernc}

\begin{document}

This is a
{\def\UrlBreaks{\do\y}%
\url{http://reallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongurl}}
which
\LaTeX\ will be unhappy about. So, how can we split this in the best way?

Here is another one which I don't want to split,
\url{http://notquitesolongastheotheroneurl}.

\end{document}


You can define a \longurl macro that will locally set \UrlBreaks to do it. For instance:

\newcommand{\longurl}[1]{%
{\expandafter\def\expandafter\UrlBreaks\expandafter{\UrlBreaks\UrlOrds%
\do\/\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}%
\url{#1}}%
}