This question was phrased as a bug report for LaTeX and I thought it would be helpful to be presented here (including an answer).

The person had a lot of "common words" in typewriter font sprinkled around his text and he was surprised that this text would not automatically hyphenate and he had to manually insert \- to mark hypenation points.

3 Answers 3


In LaTeX it is standard behavior that typewriter fonts do not do any hyphenation because it is typically used for code. Thus, the fonts used normally for \texttt all suppress hyphenation automatically.

To change this, there are essentially three options:

  • enable hyphenation for the fonts used by \texttt throughout the document
  • define your own variant of \texttt that enables hyphenation inside
  • use different a font that has hyphenation enabled automatically

Generally enabling hyphenation on \texttt

The hyphenation status is normally tied to the font family. For example, the default font used for typewriter in LaTeX is "Computer Modern Typewriter" (i.e., cmtt) and its font family definition is

\DeclareFontFamily{OT1}{cmtt}{\hyphenchar \font=-1}

for the OT1 font encoding. The "-1" means do not use a hyphenation character. A value between 0 and 255 would mean use the character in that particular slot as a hyphenation character.

Once all fonts have been set up one can alter the font family declaration for the typewriter font in a generic way (thanks to @greg) as follows:


This declaration sets the \hyphencharto the slot used by "-" in the current font for the default typewriter font family (\ttdefault) in the default encoding (\encodingdefault).

An explicit setting for a single family in one encoding would be:

\DeclareFontFamily{T1}{cmtt}{\hyphenchar \font=45}

Instead of 45 (which is the position of "-" in OT1 or T1 encoding) there is also the posibility to select an alternate hyphenation character if T1 encoded fonts are used. This alternate hyphenation character is in slot 127 in this encoding.

Defining your own tt command with hyphenation enabled

If one wishes to have both possibility with and without hyphenation that it is possible to define a separate command, for example


The trick is to not only set the fontfamily but also enable the \hyphenchar for the current font. Please note the \relax after the 45. It is necessary to make sure that TeX stops scanning for a number (a blank would have worked too). Otherwise your argument #1 could become part of the number if it happened to start with a digit.

Unfortunately there is an issue with this approach: assignments to font parameters are always global, so the above definition would also change \texttt's behavior as well (thanks to @mhp for pointing this out). This could be fixed with a similar \DeclareTextFontCommand with a setting of -1 for the hyphen. However, there may also be \ttfamily commands and they would also be affected. So a fully working solution unfortunately requires to also update that command.


Use a typewriter font with hyphenation already enabled

Within Computer Modern there is not only Computer Modern Typewriter but also another typewriter font which looks similar but has variable width characters. That font has hyphenation automatically enabled and since it is using different widths for different characters it may be a good choice in a document using a lot of typewriter text. So here one could define a command like

\newcommand\textvtt[1]{{\normalfont\fontfamily{cmvtt}\selectfont #1}}
  • You should really make a trickier definition of \mytexttt for the reasons discussed below tex.stackexchange.com/a/13436/575. \def\mytexttt#{\bgroup\hyphenchar\font=45\relax\let\next=} will set the hyphenchar without reading the argument first.
    – Ryan Reich
    Feb 13, 2012 at 8:36
  • 6
    Wouldn't \DeclareFontFamily{\encodingdefault}{\ttdefault}{\hyphenchar\font=\- }` be good?
    – egreg
    Feb 13, 2012 at 8:45
  • 1
    @egreg good point. That would be a better solution for the first case. Will update. Feb 13, 2012 at 10:45
  • 3
    @FrankMittelbach: It should be noted that the assignment \hyphenchar\font=45 is global. So starting with the paragraph where \mytexttt is used the first time, words typeset with \texttt are hyphenated, too.
    – mhp
    Nov 13, 2012 at 11:30
  • 1
    @mhp thanks for pointing this out; completely forgot that font parameters are global (the N in NFSS is obviously too long ago :-) ). Updated the solution accordingly Nov 13, 2012 at 14:55

The hyphenat-package works fine.

  • 6
    I added it to the list of packages, but it didn't do anything for me.
    – xApple
    Jul 3, 2016 at 21:08
  • 1
    Has one issue, I'd love to use this, but it doesn't let me define what hyphenation character to use. Jun 17, 2019 at 12:06

Unfortunately none of the original answers worked for me (\DeclareFontFamily...{\hyphenchar ...}, \DeclareTextFontCommand{\mytexttt}{...}, \newcommand\textvtt[1]{...} or \usepackage[htt]{hyphenat}).

What worked was taken from this post: Line break in texttt

  • How does this answer the question about automatic hyphenation in typewriter type?
    – egreg
    Jul 19, 2022 at 21:51
  • Well, without that code the words inside \texttt{} were not breaking (I was getting many "overfull hbox" warnings)...
    – moser
    Jul 21, 2022 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .