Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.


The text contains programming variable names such as report_city and SUBREPORT_FILE. All such variables are marked up with \texttt.


Some variable names are hyphenated:


I would prefer that the variables are not subjected to hyphenation.


A few ideas:

  • Redefine \texttt to wrap an \mbox{...} command around the content. Best solution?
  • Use \uchyph0. Did not work as expected.
  • Define all the words using \hyphenation{...}. The command \hyphenation{SUBREPORT\_FILE} did not compile, and defining all the words would be a second last resort.
  • Edit the entire document and put all variables inside \mbox{...} commands. I would consider this a last resort.


How would you prevent the texts from being hyphenated?

Thank you!

share|improve this question
why can't you use \verb|...| or \lstinline|...| ? –  Herbert Jan 25 '11 at 9:33
@Herbert: There are hundreds, if not thousands of instances. I would prefer not to re-edit them all. –  Dave Jarvis Jan 25 '11 at 9:34
@Dave: ok, but it is only a search and replace which can be done in one run over all files with eg Perl –  Herbert Jan 25 '11 at 9:36
@Herbert: The document is being edited with LyX. As such, I would prefer keeping everything as \texttt, rather than adding more evil red text. But that is a possibility. –  Dave Jarvis Jan 25 '11 at 9:38
@Dave: did you load the package hyphenat? If yes then comment it out –  Herbert Jan 25 '11 at 9:52
show 2 more comments

3 Answers

up vote 3 down vote accepted

I have this break because latex doesn't like underscores in text mode, but I presume you have a way round this...

share|improve this answer
LyX automatically escapes the underscores (\\_). And thank you. This works flawlessly. –  Dave Jarvis Jan 25 '11 at 17:59
@Dave Aha! That's clever of LyX. –  Seamus Jan 26 '11 at 8:33
add comment

The problem is not the texttt as is evident from the short code below!

\def\printhyphens{\everypar{\setbox0\lastbox \setbox1\hbox{\strut}\vbox\bgroup
\everypar{\setbox0\lastbox \nobreak\hskip0pt\relax}\dimen0=\hsize
\hsize=0pt \hfuzz\maxdimen \def\par{\endgraf \hsize=\dimen0\getlastline

\def\breakafterword{\catcode`\^^M\active\catcode`\ \active}
{\breakafterword\gdef^^M{\par}\global\let ^^M}




photograph photography photographer
photographical photographically



If we can see a minimal may be someone can find a solution!

share|improve this answer
The problem is breaking at underscores. Underscores cause an error on my system. So we need to know what @Dave Jarvis is doing with underscores to see the problem. –  Seamus Jan 25 '11 at 13:49
@Seamus it appears as the most likely cause for this. –  Yiannis Lazarides Jan 25 '11 at 14:41
Thank you for taking the time to look into this. –  Dave Jarvis Jan 25 '11 at 18:38
add comment

It might help to put

\texttt{\hyphenchar\font=-1 }

early in your document. But I wonder why it is needed: When I try, the hyphenchar of the texttt font is already set to -1, as evidenced by running


But maybe you are using a different fixed-width font?

share|improve this answer
Thank you. LyX defines a "TypeWriter" font, which marks-up the text using \texttt'. –  Dave Jarvis Jan 25 '11 at 17:38
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.