How can I temporarily forbid hyphenations (or make them more "expensive"), for a particular piece of text? One or two paragraphs.
2 Answers
Following the discussion in How to reduce the number of hyphenation?, you could define an environment that sets some hyphenation-avoiding parameters:
\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newenvironment{nohyphen}
{\tolerance=1% Also consider setting \pretolerance
\emergencystretch=\maxdimen%
\hyphenpenalty=10000%
\hbadness=10000}% \begin{nohyphen}
{\par}% \end{nohyphen}
\begin{document}
\lipsum[1]
\begin{nohyphen}
\lipsum[1]
\end{nohyphen}
\end{document}
The parameter selection was taken from Justify without hyphenation and, as suggested in the first post, may require some tweaking. More on this, including a discussion regarding the above parameters, is available from the TeX FAQ entry Stopping all hyphenation.
With regards to line-breaking and some of the considerations on TeX's side, also review (La)TeX makes overfull lines:
TeX’s first attempt at breaking lines is performed without even trying hyphenation: TeX sets its “tolerance” of line breaking oddities to the internal value
\pretolerance
, and sees what happens. If it can’t get an acceptable break, TeX adds the hyphenation points allowed by the current patterns, and tries again using the internal\tolerance
value. If this pass also fails, and the internal\emergencystretch
value is positive, TeX will try a pass that allows\emergencystretch
worth of extra stretchability to the spaces in each line.In principle, therefore, there are three parameters (other than hyphenation) that you can change:
\pretolerance
,\tolerance
and\emergencystretch
.
For a short text (a word) use
\mbox{content}
.\documentclass{article} \begin{document}\noindent \begin{minipage}{2cm} content content\\content \mbox{content} \end{minipage} \end{document}
For one word through the entire document use
\hyphenation{content}
in the preamble.- For a paragraph or more use
\raggedright
(this will drop justification, though). For an integer amount of paragraphs you can set penalties:
\tolerance=1 \emergencystretch=\maxdimen \hyphenpenalty=10000 \hbadness=10000
-
I'd like it with a bit longer text (one or two paragraphs). Can you suggest a way, without dropping the justification? Sep 27, 2012 at 3:26
-
1@MayGodBlessKnuth I've updated my answer but Werner was a little bit faster. I recommend to use an environment like he did so that you don't forget the
\par
or the blank line. Sep 27, 2012 at 3:46 -
I don't understand; How come setting
\rightskip
to0pt plus 1fil
removes hyphenation? TeXbook says “this isn’t a particularly good way to make ragged-right margins, because the infinite stretchability will assign zero badness to lines that are very short.”– morbusgSep 27, 2012 at 4:01 -
2@morbusg There's no penalty for using infinite stretch (
plus 1fil
), but there's a penalty for hyphenating a word. That's why the line-breaking algorithm will choose not to hyphenate. Some people (e.g. David Carlisle I think) prefer to put\rightskip 0pt plus 7em
(or any other finite value at your wish), which leads to most words not being hyphenated, but when the line would be too short, they get hyphenated.– yo'Sep 27, 2012 at 8:02