In Polish typography, one should avoid putting prepositions at the end of the line.
Nie wiedziałem, że nie umieszcza się przyimków na
końcu strony.
- bad
Nie wiedziałem, że nie umieszcza się przyimków
na końcu strony.
- good

Can I force LaTeX to put ~ after every word that is a preposition (e.g. w, z, na, o etc...) so I don't need to put them manually?

  • 7
    There is an attempt by Petr Olšák for Czech and Slovak, but it requires an extension to TeX and is not for the faint of heart. Get used to type w~ and you'll be OK.
    – egreg
    Mar 6, 2012 at 10:24
  • 1
    you mean without any sort of document markup? that would require to automatically analyse text. Not impossible in theory, but certainly nothing that LaTeX is being set up for I'd say. Mar 6, 2012 at 10:26
  • 4
    Paul Isambert's xesearch package might be up to the task (the user manual is worth seeing, with some nice effects). Mar 6, 2012 at 10:46
  • 1
    I think I've seen some Lua-based approach with a similar case (I of course can't remember the detail).
    – Joseph Wright
    Mar 6, 2012 at 10:55
  • 1
    Why not just do the replacement with a preprocessing script? I bet you could even use write a arara rule to run the script prior to compiling.
    – StrongBad
    Feb 18, 2013 at 23:54

2 Answers 2


Well, I know about a few "solutions" (in quotation marks, since - as was mentioned in the comments - this is something quite difficult to do automatically).

  1. The impnattypo package (http://ctan.org/pkg/impnattypo). Requires lualatex, and (among other interesting things) puts hard spaces after one-letter words. (Notice that your example was hypercorrect (see http://en.wikipedia.org/wiki/Hypercorrection), in a sense that in fact you may put "na" at the end of the line in Polish typography (as opposed to "a", "i", "o", "w" and "z"; I'm not sure about "we" and "ze"). While putting a tie ("~") after "na" etc. might be a good idea in some cases, I wouldn't advise to do it automatically - it'd be better to have each case judged by a human.)

  2. There is a set of macros (for plain or LaTeX, I believe) by Przemysław Scherwentke, described in the GUST Bulletin 23 (2006), pp. 109-110. AFAIR they work even with plain vanilla Knuthian TeX, but do their job by messing with active characters, which might be a bit dangerous. AFAIK it is not available on the web, but I could scan it for you and send in an email if you want.

  3. And finally, there are numerous scripts and plugins for editors to do this. As a heavy emacs addict, I know only of (two) emacs solutions. There is sierotki.el, which does two things: first, it may make your space key "electric", so that a space after a one-letter word automatically becomes a tie; second, it has a function tex-hard-spaces, which does a query-replace-regexp with suitable parameters. Actually, in current versions of sierotki.el, tex-hard-spaces is just an alias for the latter solution: tildify-buffer, which is a better one, since it can automatically detect things like math mode or verbatim, and not touch these. One (very little) problem with tildify-buffer might be its default configuration, which is suited for the Czech language; however, adapting it to Polish is a question of editing one regexp.


This is the mentioned style (comments are, alas, in Polish):

% Przemyslaw Scherwentke
% Przemyslaw.Scherwentke@pwr.wroc.pl
% Najprostsza moľliwa (?) wersja zbioru do panowania 
% nad wiszĄcymi literami. 
% Rozszerzenie .STY tylko formalne
% Nie dzia�a z tworami typu \section.
% StĄd prze�Ączniki \spaceactive, \spacespace
% do uľycia wok˘� nich
% i analogiczna zmiana kategorii ^^M.
% Przyj©te sĄ pewne dodatkowe za�oľenia, 
% �atwo widoczne z kodu, w szczeg˘lno�ci
% obs�ugiwanie (formalnie) tylko podw˘jnej spacji.


\def\spaceactive{\catcode`\ =\active}
\def\spacespace{\catcode`\ =10}
\def\CRCR{\catcode`\^^M=5}% oczywi�cie nie \crcr

\def~{\penalty10000\ }

\spaceactive% i teraz waľne sĄ procenty

\def #1#2#3{% moľna rozbudowa† wg wzoru
\if\noexpand \noexpand#1\advance\war4\fi%
\if\noexpand \noexpand#2\advance\war2\fi%
\if\noexpand \noexpand#3\advance\war1\fi%
\def\sprawdz##1{% tu sĄ znaki <TAB>
\ifcase##1{ }#1#2#3\relax% 0 --- #1#2#3 %bez tego \relax «le CR/LF
\or{    }#1#2{  }%  1 -- #1#2 spacja, wi©c s�owa dwuliterowe
\or{    }#1~#3% 2 #1 spacja #3
\or{    }#1~%  3 #1 spacja spacja
\or{    }#2#3% 4 spacja #2#3
\or{    }#2~% 5 spacja #2 spacja
\or{    }#3% 6 spacja spacja #3
\or{    }% 7 --- 3 spacje
\else BLAD\fi}%
\war0\relax}% to \relax zapobiega wch�anianiu liczb
\ifcase##1\relax{   }#1% 0
\or{\par}% 1
  • The {} functionality in the editing window allows you to format your code to show properly. Feb 18, 2013 at 23:52

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