# Prevent line-breaking after short words

The publisher requires that most of short words (shorter then 4 chars, and all the prepositions, etc.) should not be left last on the line but kept with the following word.

Wrong:

Following the last theorem, we
can see that ...


Right:

Following the last theorem,
we can see that ...


Yes I can use sed to replace such spaces with ~ but that's not right a solutionas it will affect math.

P.S. We are using a standard extbook class. Thanks in advance.

-
You might also be interested in handling hyphenations. –  Stephen Dec 17 '12 at 19:26
Thanks Stephen, hyphenation is already OK. –  saabeilin Dec 17 '12 at 19:43
Good, I just thought that there might have been some rule regarding the minimal number of letters before/after a hyphenation, in which case Egreg's linked answer would have been helpful. Anyway, maybe somebody else looking at your question can be helped by Egreg's answer to the other question. –  Stephen Dec 17 '12 at 19:48

If you can not accurately spot your math markup using sed/perl etc You could insert \shortwordspace rather than ~ directly and then define
 \protected\def\shortwordspace{\ifmmode\else~\fi}

Thanks David, I thought there is something like \shortwordpenalty for controlling that. –  saabeilin Dec 17 '12 at 15:28