tags:

views:

4644

answers:

4

How can I prevent LaTeX from inserting linebreaks in my \texttt{...} or \url{...} text regions? There's no spaces inside I can replace with ~, it's just breaking on symbols.

Update: I don't want to cause line overflows, I'd just rather LaTeX insert linebreaks before these regions rather than inside them.

+3  A: 

Surround it with an \mbox{}

Michiel Buddingh'
Will this encourage LaTeX to insert a linebreak before the region if it would overflow the line?
rampion
No. The `\nohyphens{}` command, found in the `hypenat` package, just might.
Michiel Buddingh'
Thanks for the suggestion. I just tried \nohyphens{\url{...}}, and it still allows linebreaks.
rampion
A: 

Also, if you have two subsequent words in regular text and you want to avoid a line break between them, you can use the ~ character.

For example:

As we can see in Fig.~\ref{BlaBla}, there is nothing interesting to see. A~better place..

This can ensure that you don't have a line starting with a figure number (without the Fig. part) or with an uppercase A.

Uri
+1  A: 

\mbox is the simplest answer. Regarding the update:

TeX prefers overlong lines to adding too much space between words on a line; I think the idea is that you will notice the lines that extend into the margin (and the black boxes it inserts after such lines), and will have a chance to revise the contents, whereas if there was too much space, you might not notice it.

Use \sloppy or \begin{sloppypar}...\end{sloppypar} to adjust this behavior, at least a little. Another possibility is \raggedright (or \begin{raggedright}...\end{raggedright}).

Jouni K. Seppänen
+3  A: 

Define myurl command:


\def\myurl{\hfil\penalty 100 \hfilneg \hbox}

I don't want to cause line overflows, 
I'd just rather LaTeX insert linebreaks before 
\myurl{\tt http://stackoverflow.com/questions/1012799/} 
regions rather than inside them.

Alexey Malistov