[Tex/LaTex] Avoid Single Letters at the End of Lines [Polish Language Rule]

typography

I'm writing the thesis in Polish language and one of our typography rule is that there can't be single letter at the and of line, like (w and i):

Tomek poszedl do sklepu w % <-- not allowed
mieście, żeby kupić jabłka i % <-- not allowed
bułki

I'm using LaTeX and the solution proposed by @topskip in this post:

one-letter word at the end of line

produce multiple errors during compliation. Additionaly, this content was posted few yeras ago. So I'm wondering is there any new tip that can solve my problem?

Best Answer

You are using LaTeX (i guess pdflatex) and not LuaTeX which was used in the referred solution. Am I right?


Before You Start Your Thesis / Document

Following the LaTeX wikibook (link) about the internationalization in the case of Polish:

Polish has many single letter connectives [...] To ensure that LaTeX won't set them as last letter in the line, you have to use non breakable space [...]

i~słodka
a~także
i~ciała
i~Basi

So the solution is to simply connect the following word with a ~ (tilde, also known as a non breakable space).

The non breakable space feature of the tilde character is a core LaTeX feature (thanks at @DavidCarlisle).


By the way, I googled for polish single letter latex and the solution was the third entry in my hit list.


When You Have Already Finished Your Document

Maybe you can use a text editor like Notepad++ (https://notepad-plus-plus.org/) and search and replace _z_, and _w_ and so on with _z~, and _w~ and so on (with _ I want to indicate a space).

Notepad++ also can search and replace in multiple files at once. Be sure that you try it on a backup copy of your actual document!

enter image description here

With regular expressions you may be able to have even more sophisticated ways. But I do not know much about that.