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

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?

• Lua(La)TeX changed 'recently'. Most likely you need \usepackage{luatex85} (and other remedies ;-))
– user31729
Dec 27, 2016 at 22:37
• See tex.stackexchange.com/questions/46955/…. In my answer you must disable macros before new section. But you will not problems in reading comments, because they are in Polish. Dec 27, 2016 at 23:17
• I updated the title of the question. I hope that's ok for you. I think the new title is more accurate and Google-friendlier. Dec 28, 2016 at 0:03

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.

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!

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

• Yes you are right, I am using LaTeX, precisely pdflatex. I know this solution, but when the thesis has more than 50 pages it becomes quite exhausting to straighten up all the single letters at the end of line. Dec 27, 2016 at 22:58
• @barnaba At least the solution will help others which are about to start writing. Maybe you can use an text editor like notepad++ (notepad-plus-plus.org) and search and replace "space"z"space", and "space"w"space" and so on with "space"z~, and "space"w~ and so on. Dec 27, 2016 at 23:01
• ~ is core latex (and plain tex) not babel Dec 27, 2016 at 23:05
• @DavidCarlisle Thanks for the clarification. I updated my answer accordingly. Dec 27, 2016 at 23:17
• Thank you @Dr. Manuel Kuehner, for me that's the easiest and the quickest solution, and what is the most important it works perfectly! Dec 27, 2016 at 23:58

here's a command I used for this (I had several .tex files to modify):

find -name "*.tex" -exec sed -i 's/$$[^0-9\| ]$$ $$[^\|]$$/\1~\2/g' {} \;


It adds non-breakable space after a single character in between spaces that is not a number, a pipe or a space itself.

• Welcome to TeX.SX! You probably should add an OS-remark. May 28, 2017 at 15:02

With the latest version of babel (3.58) with luatex there is predefined ‘transform’ for this purpose (also available in Czech and Slovak):

\documentclass{article}

\usepackage[polish]{babel}

\babelprovide[transforms = oneletter.nobreak]{polish}

\begin{document}

\hsize=1pt

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

\end{document}