summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/polski/plprefix.dtx
blob: aeda37360681c86955fe088d88fe362edc640fce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
% \iffalse  -*- doctex -*-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                      %%
%%                        Package plprefix                              %%
%%                                                                      %%
%% Purpose: to provide various variants of prefix notation for          %%
%%          Polish diacritical characters.                              %%
%%                                                                      %%
%% Copyright (c) by Marcin Woli\'nski                      <2003/01/09> %%
%%                  wolinski@gust.org.pl                                %%
%%                                                                      %%
%%                                                                      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%                                                                      %%
%% The package may be used freely, but you are not allowed to modify    %%
%% this file.  If you wish to make any changes please make a copy       %%
%% under a different name.                                              %%
%%                                                                      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \fi
% 
% \CheckSum{255}
% \def\plpref{\textsf{plprefix}}
% \def\popolsku{\textsc{polski}}
% 
% \prefixing
% \title{Prefiksowa notacja polskich znak/ow diakrytycznych.\\
%        Pakiet \plpref}
% \author{Marcin Woli\'nski}
% \date{9 stycz/nia 2003}
% \maketitle
%
%
% \section*{Wst/ep}
% Notacja prefiksowa (,,ciachowa'') polega na zapisywaniu polskich
% znak/ow diakrytycznych w~postaci dw/och znak/ow: \textit{prefiks}
% oraz \textit{litera} (oba znaki o kodach $\leq127$).  W~systemach,
% w~kt/orych nie daje si/e w~spos/ob naturalny wy/swietla/c na ekranie
% polskich znak/ow, taki zapis jest stosunkowo atrakcyjn/a alternatyw/a
% dla stosowania standardowych makr \LaTeX a dla akcent/ow (|\'|, |\.|
% i |\k|).
% 
% Niestety w/sr/od polskich \TeX nik/ow nie ma zgodno/sci co do tego,
% jaki znak powinien s/lu/zy/c jako prefiks.  W czasach
% prehistorycznych u/zywany bywa/l znak \texttt{@}, w /srodowiskach
% zbli/zonych do Wydzia/lu Matematyki UW nadal popularna jest notacja
% z czudzys/lowem (\texttt{"}), za/s od pojawienia si/e \MeX a na
% popularno/sci zaczyna zyskiwa/c slash (,,ciach'' \texttt{//}).  To
% jednak nie koniec problemu, bowiem nie ma r/ownie/z zgodno/sci, jak
% zapisywa/c litery /x i /z.  Spotykane wersje to prefiks-x $\to$ /x i
% prefiks-z $\to$ /z oraz prefiks-z $\to$ /x i prefiks-r $\to$ /z.  
%
% Pakiet \plpref\ stanowi dodatek do pakietu \popolsku,
% umo/zliwiaj/acy wyb/or u/zywanej notacji prefiksowej.  Mnogo/s/c
% pogl/ad/ow w kwestii notacji nale/zy jednak uzna/c za niekorzystn/a
% i promowa/c jedn/a notacj/e (w/la/sciwym kandydatem wydaje si/e
% notacja \MeX a).  Inaczej m/owi/ac stosowanie pakietu \plpref\ nie
% jest zalecane jako /ze ,,oficjaln/a'' notacj/e prefiksow/a
% obs/luguje pakiet \popolsku.  Pakiet \plpref\ zosta/l stworzony z
% my/sl/a o umo/zliwieniu u/zytkowania \LaTeX a wszystkim
% nieszcz/e/snikom, kt/orzy po prostu nie s/a w stanie patrze/c na
% ciacha, marz/a za to o swojskim cudzys/lowie lub czym innym.
% 
% \section{Instrukcja u/zytkownika}
% 
% Pakiet \plpref\ /laduje si/e przy pomocy deklaracji |\usepackage|.
% Aby dokona/c wyboru notacji nale/zy poda/c jako opcj/e zamierzony
% spos/ob wprowadzania litery /z.  Poni/zsza tabela przedstawia
% dost/epne mo/zliwo/sci.
% 
% \begin{center}
% \nonprefixing
% \begin{tabular}{ccccccccccl}
% Opcja &\k a&\'c&\k e&\l&\'n&\'o&\'s&\'z&\.z\\
% \tt/z    &/a&/c&/e&/l&/n&/o&/s&/x&/z&domy\'slna, \MeX\\
% \tt/r    &/a&/c&/e&/l&/n&/o&/s&/z&/r\\
% \tt"z    &"a&"c&"e&"l&"n&"o&"s&"x&"z\\
% \tt"r    &"a&"c&"e&"l&"n&"o&"s&"z&"r\\
% \tt@z    &@a&@c&@e&@l&@n&@o&@s&@x&@z\\
% \tt@r    &@a&@c&@e&@l&@n&@o&@s&@z&@r
% \end{tabular}
% \end{center}
% 
% Na przyk/lad nast/epuj/aca deklaracja zadaje notacj/e, w kt/orej
% prefiksem jest znak \texttt{@}, liter/e /z zapisuje si/e jako
% \texttt{@r}, natomiast /x jako \texttt{@z}:
% \begin{verbatim}
% \usepackage[@r]{plprefix}
% \end{verbatim}
% 
% W ka/zdym przypadku aby uzyska/c znak u/zywany jako prefiks nale/zy
% napisa/c go dwa razy. W przyk/ladzie powy/zej aby uzyska/c
% znak ,,at'' (@) piszemy \texttt{@@}.
%
% Ponadto aby pozosta/c w zgodno/sci z pakietem \popolsku\ w
% wersji 1.01 zosta/ly dodane nast/epuj/ace kombinacje:
% \mbox{\emph{prefix}-\texttt{,}} --- otwieraj/acy cudzys/l/ow polski,
% \mbox{\emph{prefix}-\texttt{'}} --- zamykaj/acy cudzys/l/ow polski,
% \mbox{\emph{prefix}-\texttt{<}} --- otwieraj/acy cudzys/l/ow francuski,
% \mbox{\emph{prefix}-\texttt{>}} --- zamykaj/acy cudzys/l/ow francuski,
% \mbox{\emph{prefix}-\texttt{-}} --- \verb+\dywiz+.  Na przyk/lad przy
% aktywnej deklaracji powy/zej nast/epuj/acy zapis jest poprawny:
% \begin{verbatim}
% Jan powiedzia@l: @,Marysia powiedzia@la: @<Wychyli@lam
% puchar @r@o@lto@-zielonej @r@o@lci@>@'.
% \end{verbatim}
%
% Pakiet w trakcie /ladowania nie uaktywnia notacji prefiksowej,
% poniewa/z je/zeli po nim /ladowane s/a jakie/s inne pakiety mog/loby
% to powodowa/c nieoczekiwane skutki.  \DescribeMacro{\prefixing}%
% /Zeby uaktywni/c notacj/e prefiksow/a nale/zy jawnie u/zy/c
% polecenia |\prefixing|.  Polecenie to jest zwyk/l/a lokaln/a
% deklaracj/a.  U/zyte wewn/atrz grupy obejmuje swoim zasi/egiem tekst do
% ko/nca tej grupy.  \DescribeMacro{\nonprefixing}Je/zeli
% zachodzi potrzeba wy/l/aczenia prefiksowania nale/zy u/zy/c polecenia
% |\nonprefixing|, kt/ore r/ownie/z jest deklaracj/a lokaln/a.
%
% Notacja prefiksowa nie podlega automatycznemu wy/l/aczeniu w obr/ebie
% /srodowiska \texttt{verbatim}.  Jest to r/o/znica w stosunku do \MeX a,
% natomiast jest to zgodne z zachowaniem pakietu \popolsku.  Zgodnie z
% argumentacj/a Mariusza Olko, taki uk/lad daje mo/zliwo/s/c uzyskania
% polskich znak/ow w obr/ebie /srodowiska \texttt{verbatim}, je/zeli za/s
% nasz/a intencj/a jest efekt jak w \MeX u, wystarczy jawnie wy/l/aczy/c
% prefiksowanie.
% 
% 
% \begin{small}
% \plpref\ pozwala na zastosowanie dowolnego znaku
% jako prefiksu. \DescribeMacro{\SetPrefixChar}Mo/zna to osi/agn/a/c przy
% pomocy deklaracji |\SetPrefixChar| podaj/ac jako argument znak, kt/ory
% od tej pory ma s/luzy/c jako prefiks. Oto przyk/lad sytuacji w kt/orej
% okaza/lo si/e to potrzebne (nieco egzotyczny ale prawdziwy): sk/ladamy
% w j/ezyku polskim dokumentacj/e programu komputerowego, program jest
% napisany z u/zyciem \texttt{CWEB}a. Znaki \texttt{//} i |"| maj/a
% istotne znaczenie dla j/ezyka C i ich podwajanie og/lupi/loby
% kompilator, natomiast |@| ma specjalne znaczenie dla
% \texttt{CWEB}a. W tym przypadku zastosowano do zapisywania polskich
% liter znak |`|, kt/ory szcz/e/sliwie nie by/l potrzebny do uzyskania
% cudzys/low/ow, bo tekst by/l \emph{po polsku}.
%
% Druga interesuj/aca mo/zliwo/s/c to definiowanie nowych kombinacji
% \emph{prefiks//litera}.  \DescribeMacro{\Prefix} Osi/aga si/e to przy
% pomocy makra |\Prefix|.  Na przyk/lad nast/epuj/ace linie definiuj/a
% kombinacj/e \emph{prefix}|<| (np. |//<| je/zeli prefiksem jest ciach)
% jako lewy cudzys/l/ow francuski, \emph{prefix}|>| jako prawy cudzys/l/ow
% francuski, natomiast \emph{prefix}|g| jako napis \texttt{g/lupi pomys/l?}.
% \begin{verbatim}
% \Prefix\let <\guillemotleft
% \Prefix\let >\guillemotright
% \Prefix\def g{g/lupi pomys/l?}
% \end{verbatim}
% Od tej pory zapis |Czy //<//zmir//lacz//> to //g| b/edzie znaczy/l 
% ,,Czy \guillemotleft /zmir/lacz\guillemotright\ to g/lupi pomys/l?''.
% \end{small}
% 
% \StopEventually{}
% \iffalse 
%<*driver>
  \documentclass{ltxdoc}
%<driver>% You may need to add an option to select font encoding here:
  \usepackage[MeX]{polski}
%<driver>% Comment in next line if you don't want to print the code
%<driver>% \OnlyDescription
   \begin{document}
   \DocInput{plprefix.dtx}
   \end{document}
%</driver>
% \fi
% \nonprefixing
% 
% \language0
% 
% \section{Source code}
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}[1996/06/01]
\ProvidesPackage{plprefix}[2003/01/09 v1.02
                 Prefix notation for Polish characters]
%    \end{macrocode}
%  \begin{macro}{\ThePrefixChar}
%   Current prefix character of category 12 (other) will be saved in
%   macro |\ThePrefixChar|. 
%    \begin{macrocode}
\newcommand\ThePrefixChar{1}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\prefixing}
%
%    \begin{macrocode}
\def\prefixing{\catcode\expandafter`\ThePrefixChar=\active
  \bgroup \uccode`\~=\expandafter`\ThePrefixChar \uppercase{\egroup
    \let~\PrefixMacro}%
  }
%    \end{macrocode}
%  \end{macro}
% 
%  \begin{macro}{\nonprefixing}
%
%    \begin{macrocode}
\def\nonprefixing{\catcode\expandafter`\ThePrefixChar=12 }
%    \end{macrocode}
%  \end{macro}
% 
%  \begin{macro}{\SetPrefixChar}
%    Now we can define operator for selecting prefix character
%    \begin{macrocode}
\newcommand\SetPrefixChar[1]{%
  \nonprefixing
  \bgroup \uccode`2=`#1\uppercase{\egroup
    \def\ThePrefixChar{2}}%
  \prefixing
  }
%    \end{macrocode}
%  \end{macro}
% 
%  \begin{macro}{\PrefixMacro}
%    Here we define prefix notation handler.  The first thing we do is
%    to check whether the prefix character is followed by an allowed
%    token.  The first test is for second identical character (or
%    macro |\PrefixMacro|), in which case we just return a current
%    prefix character with category code |<other>|.
% 
%    We assume that for all allowed prefix-token combinations there
%    are defined macros named |\pref@<token>|.  If comparison with
%    |\relax| is true the macro is not defined.  We issue an error
%    message with some help.
% 
%    \begin{macrocode}
\newcommand\PrefixMacro[1]{\ifx#1\PrefixMacro 
    \ifx\protect\@typeset@protect\else\protect\string\fi\ThePrefixChar 
  \else
  \expandafter\ifx\csname pref@\string#1\endcsname\relax 
    \PrefixingError{#1}%
  \else \csname pref@\string#1\endcsname \fi\fi
  }
%    \end{macrocode}
%  \end{macro}
% 
%  \begin{macro}{\PrefixingError}
%    When a prefixing error is encountered we ignore the prefix but
%    leave the next token since in cases like |/\end| gobbling |/| is
%    just what is needed, but gobbling both would cause a disaster.
%    \begin{macrocode}
\newcommand\PrefixingError[1]{%
  \ifx\protect\@typeset@protect
    \PackageError{plprefix}   
      {The prefix-character combination 
         \ThePrefixChar\noexpand#1 is undefined}%
      {I will ignore the prefix character.}%
  \else \expandafter\protect\ThePrefixChar \fi
  \expandafter\expandafter\expandafter#1%
  }
%    \end{macrocode}
%  \end{macro}
%
%    Now we can set default prefix character (slash).
%    \begin{macrocode}
\SetPrefixChar\/
\nonprefixing
%    \end{macrocode}
% 
%  \begin{macro}{\Prefix}
%    To declare prefix-character combinations we use this auxiliary
%    macro. One says
% \begin{verbatim}
% \Prefix\def c{foo}
% \end{verbatim}
%    to declare that prefix-|c| (eg. |/c|) should expand to
%    \texttt{foo}.  This can be used as well with |\let|,
%    |\newcommand|, |\renewcommand|, |\ifx| etc. 
%    \begin{macrocode}
\newcommand\Prefix[2]{\expandafter#1\csname pref@#2\endcsname}
%    \end{macrocode}
%  \end{macro}
%    
%  \begin{macro}{\PlPrIeC}
%    This macro is needed to protect against removing white space in
%    TOC by Polish characters that have definition ending with a macro
%    call (|\l| and |\L|).  The macro is identical to |\IeC| from
%    inputenc package, but we have to define it here not to depend on
%    inputenc.  The name is different not to cause conflict in case
%    inputenc is loaded after plprefix.
%    \begin{macrocode}
\def\PlPrIeC{%
  \ifx\protect\@typeset@protect
    \expandafter\@firstofone
  \else
    \noexpand\PlPrIeC
  \fi
}
%    \end{macrocode}
%  \end{macro}
%
%    Next come the declarations of all Polish diacritics.  Polish
%    characters are defined as normal accented letters, and we expect
%    that they will expand according to their definitions in the
%    current font encoding.
%
%    Since \LaTeX\ redefines |\'| in |tabbing| environment, and prefix
%    notation should work also there, we don't use |\'| but a nickname
%    |\@acute| defined later on.
%    \begin{macrocode}
\Prefix\def a{\k a} \Prefix\def A{\k A}
\Prefix\def c{\@acute c}  \Prefix\def C{\@acute C}
\Prefix\def e{\k e} \Prefix\def E{\k E}
\Prefix\def l{\PlPrIeC{\l}}   \Prefix\def L{\PlPrIeC{\L}}
\Prefix\def n{\@acute n}  \Prefix\def N{\@acute N}
\Prefix\def o{\@acute o}  \Prefix\def O{\@acute O}
\Prefix\def s{\@acute s}  \Prefix\def S{\@acute S}
\Prefix\def x{\@acute z}  \Prefix\def X{\@acute Z}
\Prefix\def z{\.z}  \Prefix\def Z{\.Z}
%    \end{macrocode}
%    Some  additional prefix combinations:
%    \begin{macrocode}
\Prefix\def ,{\PlPrIeC{\quotedblbase}}
\Prefix\def '{\PlPrIeC{\textquotedblright}}
\Prefix\def <{\PlPrIeC{\guillemotleft}}
\Prefix\def >{\PlPrIeC{\guillemotright}}
\providecommand*\dywiz{%
  \kern0sp\discretionary{-}{-}{-}\penalty10000\hskip0sp\relax}
\Prefix\def -{\PlPrIeC{\dywiz}}
%    \end{macrocode}
% 
%  \begin{macro}{\prefZisZkropka}
%  \begin{macro}{\prefZisZkreska}
%    Two macros for toggling between notations using [prefix-|x| for
%    \'z and prefix-|z| for \.z] and [prefix-|z| for \'z and
%    prefix-|r| for \.z].
%    \begin{macrocode}
\newcommand\prefZisZkropka{%
  \Prefix\let r\relax \Prefix\let R\relax
  \Prefix\def x{\@acute z}\Prefix\def X{\@acute Z}%
  \Prefix\def z{\.z}\Prefix\def Z{\.Z}%
  }
\newcommand\prefZisZkreska{%
  \Prefix\let x\relax \Prefix\let X\relax
  \Prefix\def z{\@acute z}\Prefix\def Z{\@acute Z}%
  \Prefix\def r{\.z}\Prefix\def R{\.Z}%
  }
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%    
% \subsection{Package options}
%    The options select requested notation for Polish characters.
% 
%    \begin{macrocode}
\DeclareOption{/z}{\SetPrefixChar\/ \prefZisZkropka
   \nonprefixing}
\DeclareOption{"z}{\SetPrefixChar\" \prefZisZkropka
   \nonprefixing}
\DeclareOption{@z}{\SetPrefixChar\@ \prefZisZkropka
   \catcode`\@=11}
\DeclareOption{/r}{\SetPrefixChar\/ \prefZisZkreska
   \nonprefixing}
\DeclareOption{"r}{\SetPrefixChar\" \prefZisZkreska
   \nonprefixing}
\DeclareOption{@r}{\SetPrefixChar\@ \prefZisZkreska
   \catcode`\@=11}
%    \end{macrocode}
%    
%    Font encoding current at begining of document can be assumed
%    default for document so we will define the nickname for |\'| then
%    (it will be slightly faster in this encoding).
%    \begin{macrocode}
\ProcessOptions
\AtBeginDocument{\let\@acute\'}
%</package>
%    \end{macrocode}
% 
% \Finale
% 
% \endinput
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}