share
TeX - LaTeXHow to prevent LaTeX from hyphenating the entire document?
[+263] [8] Splashy
[2010-11-07 05:35:49]
[ hyphenation ]
[ https://tex.stackexchange.com/questions/5036/how-to-prevent-latex-from-hyphenating-the-entire-document ]

I can't find where I can remove any kind of hyphenation and just have LaTeX just do a line break.

edit: Honestly speaking I just don't like to read hyphenation anywhere and that's the only reason why I wanted to remove it. It is a matter of style, probably unexpected in LaTeX.

The document has only a summary in a different language and I used the language packages to hyphenate properly.

(43) If you are going to typeset your document without hyphenation I strongly recommend using \raggedright to avoid large spaces between the word. - Will Robertson
(2) @WillRobertson But, the document looks too bad. In there a middle road? (for instance like \hyphenpenalty=5000) - Cyriac Antony
(1) @cyriac I guess you want the ragged2e package. - Will Robertson
(2) This isn’t precisely a way to prevent hyphenation, but unhyphenated documents will usually look much better if you turn font expansion on with microtype. (Not compatible with XeTeX, unfortunately.) This stretches the font slightly to reduce the amount of extra spacing. - Davislor
(1) \hyphenpenalty=9999 is just perfect ; all other options make big spaces after full stops, which to my mind is quite ugly. - Vincent Krebs
[+224] [2010-11-07 07:44:12] Joseph Wright [ACCEPTED]

This is discussed in detail in the TeX FAQ [1]. Summarising the information given there:

  1. You can set \hyphenpenalty and \exhyphenpenalty to 10000, which will stop hyphenation, but as TeX will still try to hyphenate this is not hugely efficient.

  2. As Joel says, you can use \usepackage[none]{hyphenat} to select a 'language' with no hyphenation at all. This works fine for a single language document, but not if you want to use babel [2] or polyglossia [3] for other language-specific effects.

  3. Setting \righthyphenmin and \lefthyphenmin to very large values will prevent hyphenation as it tells TeX that it must have more characters in the word than are going to be available. The suggested value in the FAQ is 62.

  4. You can set \hyphenchar\font=-1, which will prevent hyphenation for the current font: this is probably not the best way for an entire document but is how it is done for the tt font shape in LaTeX.

Now, of those (2) is probably the best choice. However, what you did not say is why you want no hyphenation. TeX hyphenates when it cannot find a good line break without it, so you get few hyphens in most cases. The risk with no hyphenation at all is that the output looks bad.

[1] https://texfaq.org/FAQ-hyphoff
[2] http://ctan.org/pkg/babel
[3] http://ctan.org/pkg/polyglossia

I used option 2. and it did a great job! perfectly formatted without hyphenation. thanks for all the info Joseph! - Splashy
(1) option 2. is not so perfect after all... some words are coming out of the text borders. - Splashy
(7) @Splashy: see Will's comment about using \raggedright. - Joseph Wright
@ Joseph: I saw, I tested and now I ended up wanting hyphenation back. Is there a way to remove hyphenation and still keep it aligned on both margins? - Splashy
(3) @Splashy: The issue is that in order to do that you end up with unacceptably-long gaps between words (see what happens in a word processor). You can let TeX make bigger gaps using the \sloppy macro, which will hopefully avoid text running into the margins when there is no hyphenation. However, the effect may well be very bad looking. That's really the whole point here: TeX hyphenates to keep a good appearance only when acceptable fiddling with spacing has failed. - Joseph Wright
(6) Oh, also consider loading the microtype package, as this enables some other approaches to improving spacing and reducing the need for hyphenation in many cases. - Joseph Wright
(2) @Juan: One reason why one might want to avoid hyphenation is because the journal they're submitting to forbids its use: tandfonline.com/action/…. - Sara
(1) Adding to Sara's comment, I would claim that hyphenation is for documents in their final stage (i.e. ready to print). Since those of us who submit manuscripts to journals and book publishers are not submitting "final stage" documents, there's no need to hyphenate. And most publishers do not want to receive manuscripts with hyphenations, since they don't want to guess when a hyphenated word is intended, and when it is there because of a line break. I'd recommend using \raggedright - it's the simplest solution. - Sverre
(1) @JuanA.Navarro some academic journals automatically reject all submitted articles with hyphenation or automatic wordwrap (this occurs in fields where tex is not very common) - WetlabStudent
Some institutions require theses be submitted with no hyphenation but fully justified.... - cfr
(1) @JosephWright I turned off hyphenation using \usepackage[none]{hyphenat}, but the words get out of the margins.. Is there a way to tell LateX to break the lines each time a word is too long? - Heinz Doofenschmirtz
(1) Note that option 1 and 2 silently breaks the breaklines option of the listings package. See stackoverflow.com/a/8264050/1650137 about option 2. I tested option 1 and ran into the same issue. - Zero3
Note that option 3 does not work if the babel package is used. - Zero3
@Zero3 It depends where you put the settings: I'm assume after babel has made its changes - Joseph Wright
@JosephWright You are probably right. At the end of the preamble it is not working though :/ - Zero3
(2) @JuanA.Navarro, another reason to prevent hyphenation, is that sometimes you want to copy/paste the text from LaTeX to another document. If you have hyphenation, you have to control the text to make sure the newly justified text is not hyphenated in the middle of sentences. - PLG
(1) @PLG I'm sure there are a few good reasons for deciding not to hyphenate, I just think it's good to ask oneself whether one actually wants that behavior. - Juan A. Navarro
With #2, compilation fails with Command \BreakableUnderscore already defined in my document. @TimHarris' suggestion worked for me. - CPBL
(2) @JuanA.Navarro The simple answer to "Why would you want to prevent hyphenation?" is "Because it sucks". I cannot count the number of times that I'm reading a text (done with TeX) and I see a word that is screwed up by an incorrect hyphenation after a line break. Also if you are writing a scientific paper or a similar written work hyphenation is something that is avoided in general. - rbaleksandar
(1) @rbaleksandar, I thought the TeX mechanism for hyphenation was pretty trustworthy. I've never seen a word "screwed up" by incorrect hyphenation done by Latex in several languages (yes, you do have to use babel for that to work) As far as typeset text goes, it's hard to find professional typesetting, specially in a two-column page, without hyphenation. Writing is another matter: you don't hyphenate text when you write in Latex. - user9424
@PLG, you supposedly can also copy from the source code, then there will be no hyphens at all. - user9424
@joseph Of course, but if you have a lot of latex codes in the text, then that can prove to be more work than just removing hyphens. - PLG
The \hyphenpenalty=10000 works well here. Follow a working example: \documentclass[preprint,review,12pt]{elsarticle} \hyphenpenalty=10000 \begin{document} Text, text, text. \end{document} - Yuri Gelsleichter
Note that LuaTeX manual states that \hyphenchar\font=-1 is deprecated, although it still works. - user202729
1
[+163] [2014-05-14 14:32:26] Tim Harris

I use this and it works great for me in almost all documents:

\tolerance=1
\emergencystretch=\maxdimen
\hyphenpenalty=10000
\hbadness=10000

\begin{document}... yadda yadda\end{document}

(10) Good answer, the previous solutions mess up my document, this works for me!!! - richardtk_1
(2) When I used hyphenpenalty=10000 alone some words pass the margin. This works great. - Gokce Mehmet AY
(2) This worked for me with Share Latex, and it avoids the problem of words going over the right-hand margin. - timothyjgraham
(1) This worked ultimately...Thank you so much..@Timharris - David
(5) Thank you! All of the other answers that I've seen make the words overflow into the margin rather than wrapping to the next line. - Sumner Evans
(1) This is the only answer that doesn't make the text overflow. - Diaa
(1) The only one that worked on my project. - Hugo L.M
Somehow words that already have an hyphen in them are still broken by this method. Anyway to prevent that instead? - Hielke Walinga
@HielkeWalinga Funny - I would like it to still break those, but it doesn't! :D - Eike P.
Best answer among all. - Astra Uvarova - Saturn's star
(1) This save me from tons of wasted hours!! - Neonigma
(1) Best answer. It should really be on all Latex intro books etc. It is such a shame such a simple, convenient answer to a common typographical demand isn't found so easily. - user574859
(1) Perfect. This works best for me: \emergencystretch=\maxdimen \tolerance=5000 \hyphenpenalty=5000. Note that the hbadness does not affect the layout, just the reporting of warnings. - shredEngineer
I agree with all the comments: these four lines are in a way a catch-all alternative to package microtype (microtype approach takes time to fix sentence by sentence). Very useful to know, thank you! - MattAllegro
2
[+76] [2010-11-07 05:43:00] Joel Berger

A quick google found

\usepackage[none]{hyphenat}

and more useful info here [1].

[1] http://texfaq.org/FAQ-hyphoff

(4) Note that this silently breaks the breaklines option of the listings package. See stackoverflow.com/a/8264050/1650137. - Zero3
(15) Another reason for not using hyphenation is if you want a textually 'clean' way to cut-and-paste to other editing environments. For example I cut-and-paste text from the typeset PDF that LaTeX generates into other editing packages when I work with colleagues who do not use LaTeX (and aren't likely to either). - Aldoaldo
I get badbox errors by using this. - don't train ai on me
bad link? or is the site down? ( texfaq.org/FAQ-hyphoff ) - DrBeco
3
[+35] [2011-05-30 18:23:42] egreg

If one uses babel, there's the hyphsubst package by Heiko Oberdiek:

\documentclass[a4paper]
...
\usepackage[german=nohyphenation,french=nohyphenation]{hyphsubst}
\usepackage[german,french]{babel}

provided the distribution knows about the virtual language nohyphenation that has no patterns (both TeX Live and MiKTeX should know it).

If this is not the case, the following hack is equivalent

\makeatletter\chardef\l@nohyphenation=255 \makeatother
\usepackage[german=nohyphenation,french=nohyphenation]{hyphsubst}

(at least if less than 256 languages are already defined in the format, which is quite likely).

TeX will still possibly break lines at explicit hyphens, though.


To explain it better: if you get an error about

Unknown pattern nohyphenation

then the document should be like

\documentclass[a4paper]

\makeatletter\chardef\l@nohyphenation=255 \makeatother
\usepackage[german=nohyphenation,french=nohyphenation]{hyphsubst}
\usepackage[german,french]{babel}

(1) I am sorry, but I searched hyphsubst manual for the option nohyphenation, and I got nothing. I would be grateful if you could update your answer if it needs. - Diaa
(1) @DiaaAbidou There is no nohyphenation option: the options are of the form language1=language2 and nohyphenation chooses a language with no hyphenation pattern. - egreg
I tried to compile a MWE with your code of babel, but it gives me an error Package hyphsubst Error: Unknown pattern nohyphenation.' \ProcessOptions*. Would you like me to post a new question about it? - Diaa
(1) @DiaaAbidou Then you have to follow the second strategy: “If this is not the case…” - egreg
Many thanks for your consideration. I don't want to take more from your time, but whenever you wish, I hope you can explain a bit what you meant by at least if less than 256 languages are already defined in the format, which is quite likely. I couldn't quite understand it. - Diaa
@DiaaAbidou Where's the problem? You don't have 255 languages defined in your format, do you? You can get problems only in this case, which is unlikely. Did you try the code? - egreg
I tried the code and it worked for me. I didn't quite understand your statement at the first time, and now I get it. The problem is from my side not yours. Thanks again for your help. - Diaa
(1) @DiaaAbidou You're welcome! - egreg
4
[+5] [2016-03-19 00:09:56] Zombo

You can use the command:

\raggedright

or the environment:

\begin{flushleft}
\end{flushleft}

§ Paragraph alignment [1]

[1] //wikibooks.org/wiki/LaTeX/Paragraph_Formatting#Paragraph_alignment

5
[+5] [2020-12-05 10:43:39] Alexander Braekevelt

Based on the answers from another post [1], I found these settings to be perfect to prevent hyphenation without being ugly:

\tolerance=9999
\emergencystretch=10pt
\hyphenpenalty=10000
\exhyphenpenalty=100

\tolerance=9999 allows as much whitespace as possible.

\emerencystretch=10pt allows some extra whitespace per line.

\hyphenpenalty=10000 disables hyphens completly.

\exhyphenpenalty=100 allows using hyphens which were already present.

[1] https://tex.stackexchange.com/questions/31301/how-to-reduce-the-number-of-hyphenation/

6
[0] [2020-05-09 14:24:39] Adam Lee

By increasing the width of the spaces between words, it is possible to give LaTeX more room to stretch or squeeze a line of text, thus reducing the frequency with which words have to be divided at line breaks. In many documents, the respacing achieved using the command below will virtually eliminate end-of-line hyphenation, without forcing text into the margin.

    \spaceskip=1.3\fontdimen2\font plus 1.3\fontdimen3\font minus 1.3\fontdimen4\font

In this command, \fontdimen2 is the nominal or ideal distance between words, \fontdimen3 is the allowable extension of the inter-word space and \fontdimen4 is the allowable compression.

It is perhaps worth noting also that hyphenation of a given word can be prevented manually by placing it in an \mbox{}.


This uses a different mechanism, but the result isn't greatly different from that achieved with \sloppy. - barbara beeton
7
[0] [2021-09-21 04:06:21] Muhammad Yasirroni

By using all the answer here, you might be noticed that space after period feels too wide, where you might be not noticed when there is hyphenation.

This is due to latex use more than single space after period. See the discussion in SE answer here [1].

Thus, you can add \frenchspacing to remove this behavior if you use \pretolerance=10000, and disable the french spacing using \nonfrenchspacing if you use hyphenation.

Also, if your text contain hyphenation that you write manually, you can use \tolerance=9000 and \emergencystretch=0pt to allow change line between word using that hypen. Otherwise, you can set \tolerance=1 and \emergencystretch=\maxdimen to prohibit change line between words of your manual hypen.

The MWE (based on this [2], and this [3]) will be:

\documentclass[12pt]{article} 

\tolerance=9000
\emergencystretch=0pt
\hyphenpenalty=10000
\hbadness=10000
\frenchspacing

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam eleifend tellus
id ultrices feugiat. Sed a risus vitae nisi placerat posuere. Donec ullamcorper
rhoncus purus, a ornare nunc. In tempus elementum tellus a dictum. Orci varius
natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Phasellus pharetra mollis efficitur. Duis urna nunc, molestie vitae ante in,
pharetra hendrerit arcu. Fusce varius lectus vitae leo facilisis, sed ultricies
velit interdum. Nunc volutpat, neque iaculis tempor scelerisque, enim nunc
posuere sapien, vitae tempor quam justo a odio. Suspendisse porta vel ante et
sagittis. Sed sit amet malesuada ligula, id commodo diam. Donec posuere eros et
orci dignissim tincidunt. Donec imperdiet, metus at lobortis rutrum, nisi felis
pretium magna, quis lacinia magna erat eget quam. Duis eget dolor consequat,
porttitor nunc vel, rutrum tellus. Donec semper finibus justo vel elementum.

\end{document}
[1] https://tex.stackexchange.com/a/4715/230830
[2] https://tex.stackexchange.com/a/177179/230830
[3] https://tex.stackexchange.com/a/4706/230830

8