154

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'
    Aug 17, 2012 at 14:30
  • @tohecz (c) all occurences of thatshouldnot
    – MSIS
    Aug 17, 2012 at 15:28
  • Is this similar to my question? tex.stackexchange.com/questions/100010/…
    – Jörg
    Apr 19, 2013 at 13:01
  • @Jörg Yes, it is.
    – axolotl
    Apr 29, 2018 at 8:59

2 Answers 2

183

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.

10
  • 1
    it does not work for an acronym like `K-PLUS'
    – Valerio
    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. 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 ... May 17, 2016 at 16:25
  • 1
    thanks! i've put \newcommand{\KPLUS}{\mbox{K-PLUS}\ } otherwise there is no space afterwards
    – Valerio
    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. May 17, 2016 at 19:24
165

Put it in a box:

\mbox{thatshouldnot}
5
  • 1
    If I define \newcommand{\tsn}{\mbox{thatshouldnot}} and write "Testing the \tsn command.", there is no space after thatshouldnot. Why? 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. 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. Apr 16, 2019 at 12:22
  • 2
    @ZoltánCsáti I wrote such a package, but... tex.stackexchange.com/questions/86565/drawbacks-of-xspace/… Apr 16, 2019 at 17:46
  • Try \newcommand{\tsn}{\mbox{thatshouldnot}\xpspace}
    – vy32
    Jul 31, 2021 at 2:23

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.