174

I want to put pdflatex to not put a hyphen in a word went it comes to the end of the line.

I tried to put a \- in the beginning or the end of that word but it doesn't work.

For example if I put:This is a very long sentence that needs two lines with thatshouldnot\- be hyphened I will get:

This is a very long sentence that needs two lines with thatshouldnot-
be hyphened

and if I do it this way: This is a very long sentence that needs two lines with \-thatshouldnot be hyphened I will get:

This is a very long sentence that needs two lines with -
thatshouldnot be hyphened

I want 'thatshouldnot' to stay in one word and with no hyphen in the beginning or the end of the word.

4
  • 3
    Do you want to suppress hyphenation of (a) all words everywhere, (b) all words of that paragraph, (c) all occurences of thatshouldnot, or (d) only this one word thatshouldnot ?
    – yo'
    Commented Aug 17, 2012 at 14:30
  • @tohecz (c) all occurences of thatshouldnot
    – MSIS
    Commented Aug 17, 2012 at 15:28
  • Is this similar to my question? tex.stackexchange.com/questions/100010/…
    – Jörg
    Commented Apr 19, 2013 at 13:01
  • @Jörg Yes, it is.
    – axolotl
    Commented Apr 29, 2018 at 8:59

2 Answers 2

208

if this word appears more than once in your document, and you never want it to be hyphenated, you can suppress hyphenation everywhere by putting this line in the preamble:

\hyphenation{thatshouldnot}

if it only occurs once, then david's answer using \mbox suffices.

addendum:
A language that treats an apostrophe as a letter (such as Italian; see Preventing hyphenation of a word with \hyphenation does not always work) and is processed with Xetex may not recognize an exception entered with \hyphenation. In the cited case, there are two workarounds. For the first, replace the ASCII apostrophe (U+0027) by the right single quotation mark (U+2019). \mbox should always work as a last resort.

12
  • 2
    it does not work for an acronym like `K-PLUS'
    – Valerio
    Commented May 17, 2016 at 13:01
  • 3
    that already contains a hyphen. the only practical way to suppress a break in that case is to box it. there is a "less practical" way, and that is to set \exhyphenpenalty=10000; since this will suppress breaks after all explicit hyphens, it has to be buried in a group along with the string on which it is supposed to act. Commented May 17, 2016 at 15:41
  • 4
    @Valerio -- to handle this in the preamble, you will have to make a command: \newcommand{\KPLUS}{\mbox{K-PLUS}}. it would be better, usually, to deal with it in the main text: if we consider \mbox{K-PLUS} then ... Commented May 17, 2016 at 16:25
  • 1
    thanks! i've put \newcommand{\KPLUS}{\mbox{K-PLUS}\ } otherwise there is no space afterwards
    – Valerio
    Commented May 17, 2016 at 19:00
  • 1
    @Valerio -- that will always put a space after "K-PLUS", even if it is followed by a period or comma. the xspace package is meant for use in such situations (although it's overkill, and not recommended by some high-profile users); look for information by searching in this site. Commented May 17, 2016 at 19:24
180

Put it in a box:

\mbox{thatshouldnot}
6
  • 1
    If I define \newcommand{\tsn}{\mbox{thatshouldnot}} and write "Testing the \tsn command.", there is no space after thatshouldnot. Why? Commented Apr 15, 2019 at 13:29
  • 1
    @ZoltánCsáti number 1 FAQ, the space is used to terminate the command, you can not write the \tsncommand so you need a space to end \tsn so use \tsn\ command to print a space. this is true of every tex command. Commented Apr 15, 2019 at 13:45
  • Thank you. Although it would be nice if I could simply use the mbox-ed command without needing to manually type \ in the document body whenever I want a space. Is there a solution in which I create a command which automatically inserts \ if the command is inside a sentence and does nothing when it is the last word of a sentence (followed by a full stop)? This would make the document body easier to read and type. Commented Apr 16, 2019 at 12:22
  • 2
    @ZoltánCsáti I wrote such a package, but... tex.stackexchange.com/questions/86565/drawbacks-of-xspace/… Commented Apr 16, 2019 at 17:46
  • Try \newcommand{\tsn}{\mbox{thatshouldnot}\xpspace}
    – vy32
    Commented Jul 31, 2021 at 2:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .