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!

  • 1
    why can't you use \verb|...| or \lstinline|...| ?
    – user2478
    Jan 25 '11 at 9:33
  • @Herbert: There are hundreds, if not thousands of instances. I would prefer not to re-edit them all. Jan 25 '11 at 9:34
  • 1
    @Dave: ok, but it is only a search and replace which can be done in one run over all files with eg Perl
    – user2478
    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. Jan 25 '11 at 9:38
  • 2
    @Dave: did you load the package hyphenat? If yes then comment it out
    – user2478
    Jan 25 '11 at 9:52

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

  • 1
    LyX automatically escapes the underscores (\\_). And thank you. This works flawlessly. Jan 25 '11 at 17:59
  • @Dave Aha! That's clever of LyX.
    – Seamus
    Jan 26 '11 at 8:33

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?

  • Thank you. LyX defines a "TypeWriter" font, which marks-up the text using \texttt'. Jan 25 '11 at 17:38

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!

  • 2
    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. Jan 25 '11 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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