Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In Polish typography, one should avoid putting prepositions at the end of the line.
Example:
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?

share|improve this question
6  
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 '12 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. –  Frank Mittelbach Mar 6 '12 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). –  Bruno Le Floch Mar 6 '12 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 '12 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 '13 at 23:54
show 2 more comments

2 Answers

up vote 13 down vote accepted

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.

share|improve this answer
add comment

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.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcount\war
\war0 

\def\spaceactive{\catcode`\ =\active}
\def\spacespace{\catcode`\ =10}
\def\CRactive{\catcode`\^^M=\active}
\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}%
\sprawdz\war%
\war0\relax}% to \relax zapobiega wch�anianiu liczb
\spacespace%
%%%%%%%
%\catcode`\^^M=\active%
\CRactive%
\newcount\warm%
\warm0%
\long\def^^M#1{%
\if\noexpand^^M\noexpand#1\advance\warm1\fi%
\def\sprawdzM##1{%
\ifcase##1\relax{   }#1% 0
\or{\par}% 1
\else{BLAD}\fi}%
\sprawdzM\warm%
\warm0\relax}%
%\catcode`\^^M=5%
\CRCR%
%%
share|improve this answer
    
The {} functionality in the editing window allows you to format your code to show properly. –  Peter Jansson Feb 18 '13 at 23:52
add comment

Your Answer

 
discard

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.