112

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.

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

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.

  • 2
    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. – barbara beeton May 17 '16 at 15:41
  • 3
    @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 ... – barbara beeton May 17 '16 at 16:25
  • 1
    thanks! i've put \newcommand{\KPLUS}{\mbox{K-PLUS}\ } otherwise there is no space afterwards – Valerio May 17 '16 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. – barbara beeton May 17 '16 at 19:24
  • 1
    @CiprianTomoiagă -- no, anything in an \mbox is by definition unsplittable. if you did this: \newcommand{\KPLUS}{K-PLUS} without the box, it would be splittable. the \mbox needs to be applied just at the point where a break at a hyphen is not wanted. – barbara beeton Feb 25 '18 at 14:51
124

Put it in a box:

\mbox{thatshouldnot}
  • If I define \newcommand{\tsn}{\mbox{thatshouldnot}} and write "Testing the \tsn command.", there is no space after thatshouldnot. Why? – Zoltán Csáti Apr 15 at 13:29
  • @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. – David Carlisle Apr 15 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. – Zoltán Csáti Apr 16 at 12:22
  • 1
    @ZoltánCsáti I wrote such a package, but... tex.stackexchange.com/questions/86565/drawbacks-of-xspace/… – David Carlisle Apr 16 at 17:46

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.