3

When I use

\usepackage[T1]{fontenc}%A typewriter font.
\renewcommand*\familydefault{\ttdefault}

in the preamble instead of the default font, the beautiful word-wrapping that happens no longer works and words just go off the page willy-nilly. Is there some option/package I can use to return LaTeX to normal behaviour?

Thoughts?

David Carlisle
  • 757,742
  • \ttfamily or the type writer font can't break and wrap! You've changed the font settings to use \ttdefault. Did you mean \rmdefault actually? –  Oct 16 '15 at 12:16
  • No, I did mean to set to \ttdefault to use the typewriter font. I did not know that it couldn't break and wrap. Good to know. Thanks! – Reuben Mathew Oct 16 '15 at 12:20
  • 2
  • while it is possible to re-enable hyphenation in a monospace font the result is usually rather strange which is why it is disabled by default. monospace fonts are usually set with fixed space of the same width to preserve the mono-space alignment. That means there is no flexibility to use hyphenation rules to pick a good place to break a word, all you can do is break at exactly the same number of characters at each line. – David Carlisle Oct 16 '15 at 13:28
  • @Johannes_B note that while enabling hyphenation within \texttt used for individual words can often make sense (as there is flexibility in the rest of the line) enabling hyphenation in a block of text that is all monospace is always going to poke you in the eye. – David Carlisle Oct 16 '15 at 13:31
  • @DavidCarlisle The result will be pretty ugly indeed. – Johannes_B Oct 16 '15 at 13:32
  • 1
    have you considered setting the monospace text \raggedright ? – David Carlisle Oct 16 '15 at 13:33

1 Answers1

6

Text failing to be justified, hyphenated, and set raggedright:

enter image description here

\documentclass{article}

\usepackage[T1]{fontenc}%A typewriter font.
\renewcommand*\familydefault{\ttdefault}

\setbox0\hbox{\texttt{ }}
\dimen0=\wd0
\setlength\textwidth{50\dimen0}

\begin{document}

\bigskip\hrule\bigskip

in the preamble instead of the default font, the beautiful
word-wrapping that happens no longer works and words just go off the
page willy-nilly. Is there some option/package I can use to return
LaTeX to normal behaviour?

\bigskip\hrule\bigskip

{\hyphenchar\font`\- \hyphenation{th-e w-o-r-k-s th-ere l-a-t-e-x}\lefthyphenmin=0 \righthyphenmin=0
in the preamble instead of the default font, the beautiful
word-wrapping that happens no longer works and words just go off the
page willy-nilly.\\ Is there some option/package I can use to return
LaTeX to normal behaviour?

}

\bigskip\hrule\bigskip

{\raggedright

in the preamble instead of the default font, the beautiful
word-wrapping that happens no longer works and words just go off the
page willy-nilly. Is there some option/package I can use to return
LaTeX to normal behaviour?

}

\bigskip\hrule\bigskip

\end{document}
David Carlisle
  • 757,742