# Stop hyperref from breaking lines

The different behaviors of \url and \href have been discussed here. Today I notice that href introduces line breaks where I do not want them. Is there a way to prevent that?

Things marked with \url seem to happily continue into right margin.

Usually I don't want links in the margin, but in just this one case, it is needed by a requirement of the project manager.

In the below, output has identical sentences in lines 4 and 6, only difference is that one link is \url and one is \href.

MRE:

\documentclass[12pt,english]{article}
\usepackage{lmodern}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{geometry}
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
\usepackage{babel}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
{hyperref}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{url}

\makeatother

\begin{document}
I want to insert a hyperlink, but using \textbackslash{}href uses
the hyphenation features from hyperref and I want to disable them.

\urlstyle{rm}

URL that nicely does not break:

This is a line with a URL at the end of it: \url{http://pj.freefaculty.org/scraps/some-thing-here}

Href that does break and I wish it did not:

This is a line with a URL at the end of it: \href{http://pj.freefaculty.org/scraps/some-thing-here}{http://pj.freefaculty.org/scraps/some-thing-here}

OK to write in margin, \textbackslash{}url does:

I do not mind going into the margin a little bit. \url{http://pj.freefaculty.org/scraps/some-thing-here}

A linebreak I wish I did not have:

I don't want the hyperref to spread this across lines, as you see
next.

I do not mind going into the margin a little bit. \href{http://pj.freefaculty.org/scraps/some-thing-here}{http://pj.freefaculty.org/scraps/some-thing-here}
\end{document}

• I guess you forgot a hyperlink in your "here" statement ? – BambOo Dec 12 '17 at 17:04
• Note \url{URL} show a URL but \href{URL}{foo} show the second argument (foo) that link a URL, but is not (necessarily) a URL, so processed as a normal (breakable) text. But with or without hyperrref, you always can make any text unbreakable with a \mbox (e.g., \href{URL}{\mbox{foo}}. – Fran Dec 12 '17 at 21:09