TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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


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.

share|improve this question
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
up vote 5 down vote accepted

I don't think a pure TeX solution is feasible (luatex might be possible).

If you can not accurately spot your math markup using sed/perl etc You could insert \shortwordspace rather than ~ directly and then define


so it does nothing in math mode.

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.