8

Background

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

Problem

Some variable names are hyphenated:

SUBREPORT_-
FILE

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

Solution

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.

Question

How would you prevent the texts from being hyphenated?

Thank you!

Dave Jarvis
  • 11,809
  • 1
    why can't you use \verb|...| or \lstinline|...| ? –  Jan 25 '11 at 09: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 09: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 –  Jan 25 '11 at 09: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 09:38
  • 2
    @Dave: did you load the package hyphenat? If yes then comment it out –  Jan 25 '11 at 09:52
  • What are you doing to let text mode underscores work fine? Could this be part of the problem? – Seamus Jan 25 '11 at 11:50
  • @Seamus @Dave texttt is not the problem, please see my post. – yannisl Jan 25 '11 at 11:54

3 Answers3

5
\let\temptt\texttt
\renewcommand\texttt[1]{\mbox{\temptt{#1}}}

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

Seamus
  • 73,242
2

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

\texttt{\showthe\hyphenchar\font}

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

2

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

\documentclass{article}
\usepackage{lipsum}
\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
\egroup\endgraf}}\offinterlineskip\breakafterword}

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

\def\getlastline{\setbox0\lastbox\ifvoid0\let\next\nomorelines
\else\unskip\unpenalty\setbox1\hbox{\unhbox0\strut\discretionary{}{}{}%
\unhbox1}\let\next\getlastline\fi\next}

\def\nomorelines{\unhbox1}
\begin{document}

\begingroup

\printhyphens
photograph photography photographer
photographical photographically
hypersupersuperdupercali%

\texttt{fragilisticexpihalidocious}

\texttt{photographer}
\end{document}

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

yannisl
  • 117,160
  • 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. – yannisl Jan 25 '11 at 14:41