summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/nevelok/nevelok.dtx
blob: 6128e7465fcc5a9fba1ce79c886454ca721901b9 (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
% \iffalse meta-comment
%<*internal>
\iffalse
%</internal>
%<*readme>
----------------------------------------------------------------
nevelok --- LaTeX package for automatic definite articles for Hungarian
Author:  Zalan Bodo
E-mail:  zbodo@cs.ubbcluj.ro
License: Released under the LaTeX Project Public License v1.3c or later
See:     http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

LaTeX package for automatic definite articles for Hungarian
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
----------------------------------------------------------------
nevelok --- LaTeX package for automatic definite articles for Hungarian
Author:  Zalan Bodo
E-mail:  zbodo@cs.ubbcluj.ro
License: Released under the LaTeX Project Public License v1.3c or later
See:     http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

\endpreamble
\postamble

Copyright (C) 2015 by Zalan Bodo <zbodo@cs.ubbcluj.ro>

This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License (LPPL), either
version 1.3c of this license or (at your option) any later
version.  The latest version of this license is in the file:

http://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) by
Zalan Bodo.

This work consists of the file nevelok.dtx and a Makefile.
Running make generates the derived files README.txt, nevelok.pdf and nevelok.sty.
Running make inst installs the files in the user's TeX tree.
Running make install installs the files in the local TeX tree.

\endpostamble

\usedir{tex/latex/nevelok}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/nevelok}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/nevelok}
\generate{
  \file{README.txt}{\from{\jobname.dtx}{readme}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{nevelok.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{nevelok}
%<*package>
    [2015/12/05 v1.03 LaTeX package for automatic definite articles for Hungarian]
%</package>
%<package>\RequirePackage{xstring}
%<*driver>
\documentclass{ltxdoc}
\usepackage[a4paper,margin=25mm,left=50mm,nohead]{geometry}
\usepackage[numbered]{hypdoc}
\usepackage{\jobname}
%\EnableCrossrefs
%\CodelineIndex
\RecordChanges
\newtheorem{example}{Example}[section]
\begin{document}
  \sloppy
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{\jobname.dtx}
% \DoNotIndex{\newcommand,\newenvironment}
%
%\title{\textsf{nevelok} --- \LaTeX{} package for automatic definite articles for Hungarian\thanks{This file 
%   describes version \fileversion, last revised \filedate.}
%}
%\author{Zal\'an Bod\'o\thanks{E-mail: zbodo@cs.ubbcluj.ro}}
%\date{Released \filedate}
%
%\maketitle
%
%\changes{v1.00}{2015/09/10}{First public release}
%\changes{v1.01}{2015/11/13}{Added support for referencing in captions (e.g. in figures), added extra commands
% for extended functionality, etc.}
%\changes{v1.02}{2015/09/10}{Minor bug fixes}
%\changes{v1.03}{2015/09/10}{Bug fixes}
%
% \begin{abstract}
% \LaTeX{} package for automatic definite articles for Hungarian.
% \end{abstract}
%
%\section{Introduction}
%
% In Hungarian, the definite articles ``a'' and ``az'' are determined by the
% pronounciation of the subsequent word. If the first phoneme of the pronounced word
% is a vowel, then the article is ``az'', otherwise ``a'' must be used. 
% The simple commands help the \LaTeX{} user to automatically adjust the
% definite article according to chapter, equation, page, etc. number.
%
% \section{Usage}
%
% \DescribeMacro{\aaz}
% \DescribeMacro{\Aaz}
% The \textsf{nevelok} package provides the following \emph{main} commands: \cmd{\aaz}\marg{reference}
% and \cmd{\Aaz}\marg{reference},
% where \emph{reference} is a reference to a label of a \LaTeX{} object, or simply a 
% defined label (section, equation, figure, etc.).
% The difference stands in letter casing: the \cmd{\aaz} is the lower case command
% producing ``a'' and ``az'', while \cmd{\Aaz} is the upper case version, producing
% ``A'' and ``Az'' for the beginning of a sentence.
% The commands also work if the reference is put in round parantheses.
%
% \DescribeMacro{\aazx}
% \DescribeMacro{\Aazx}
% The \cmd{\aazx}\marg{reference}\marg{s1}\marg{s2} and
% \cmd{\Aazx}\marg{reference}\marg{s1}\marg{s2} commands are the extended versions of the base \cmd{\aaz}
% and \cmd{\Aaz}
% commands, which simply put the reference between the symbols \emph{s1} and \emph{s2}.
% This is useful for example when referencing equations, where the equations' numbers are often put
% in round parantheses. 
% 
% \DescribeMacro{\aazt}
% \DescribeMacro{\Aazt}
% The \cmd{\aazt}\marg{reference} and \cmd{\Aazt}\marg{reference} commands can be used for 
% simple text, i.e. for text representing non-labels. 
%
% \textsf{Note}: The reference argument---in contrast to v1.00---must be a label, not 
% a \cmd{\ref} command. For example: \cmd{\aaz\{eq:some\_equation\}}
% 
% \textsf{Requirements}: The package requires/uses the \textsf{xstring} package.
%
% \section{Limitations}
% \subsection{Using with \textsf{babel}}
%
% The package can be used with \textsf{babel}, however, one cannot use
% \emph{shorthands}. Therefore, one has to load \textsf{babel} with the 
% \texttt{safe=none} option:
%
% \cmd{\usepackage[magyar,safe=none]\{babel\}}
%
% \subsection{Other limitations}
% 
% The numeric labels are handled correctly by the package if they are lower or equal to
% 9999. Larger numbers are planned to be handled in future versions of the package.
%
%\StopEventually{^^A
%  \PrintChanges
%}
%
% \section{Implementation}
%
% \begin{macro}{\ifUnDefinedCs}
% The \cmd{\ifUnDefinedCs} macro checks whether a command is defined, and
% is used to check for undefined labels. It is taken from \cite{Eijkhout92}.
%    \begin{macrocode}
%%
\def\ifUnDefinedCs#1{\expandafter\ifx\csname#1\endcsname\relax}%
%%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\aaz}
% The \cmd{\aaz} command outputs ``a'' or ``az'', depending on the argument.
% To be used inside the sentence.
%    \begin{macrocode}
%%
\DeclareRobustCommand{\aaz}[1]{%
  \ifUnDefinedCs{r@#1}%
    \PackageWarning{nevelok}{Reference not (yet) defined!}%
    a(z) ??%
  \else%
    \z@aaz{\ref{#1}}{a}{az}{}{}%
  \fi%
}%
%%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Aaz}
% The \cmd{\Aaz} command outputs ``A'' or ``Az'', depending on the argument.
% To be used when starting a new sentence.
%    \begin{macrocode}
%%
\DeclareRobustCommand{\Aaz}[1]{%
  \ifUnDefinedCs{r@#1}%
    \PackageWarning{nevelok}{Reference not (yet) defined!}%
    a(z) ??%
  \else%
    \z@aaz{\ref{#1}}{A}{Az}{}{}%
  \fi%
}%
%%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\aazx}
% The \cmd{\aazx} command is the extended version of \cmd{\aaz} taking 3 parameters:
% the second and third parameters will be put in the output before and after the
% reference.
%    \begin{macrocode}
%%
\DeclareRobustCommand{\aazx}[3]{%
  \ifUnDefinedCs{r@#1}%
    \PackageWarning{nevelok}{Reference not (yet) defined!}%
    a(z) ??%
  \else%
    \z@aaz{\ref{#1}}{a}{az}{#2}{#3}%
  \fi%
}%
%%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Aazx}
% The equivalent of \cmd{\aazx} for the beginning of a sentence.
%    \begin{macrocode}
%%
\DeclareRobustCommand{\Aazx}[3]{%
  \ifUnDefinedCs{r@#1}%
    \PackageWarning{nevelok}{Reference not (yet) defined!}%
    a(z) ??%
  \else%
    \z@aaz{\ref{#1}}{A}{Az}{#2}{#3}%
  \fi%
}%
%%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\aazt}
% The equivalent of \cmd{\aaz} for simple, non-label text.
%    \begin{macrocode}
%%
\DeclareRobustCommand{\aazt}[1]{%
  \z@aaz{#1}{a}{az}{}{}%
}%
%%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\Aazt}
% The equivalent of \cmd{\aazt} for the beginning of a sentence.
%    \begin{macrocode}
%%
\DeclareRobustCommand{\Aazt}[1]{%
  \z@aaz{#1}{A}{Az}{}{}%
}%
%%
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\z@aaz}
% The main command of the package, used by the two provided commands:
% \cmd{\z@aaz}\marg{reference}\marg{art1}\marg{art2}\marg{sym1}\marg{sym2}.
% The \emph{art1} and \emph{art2} parameters stand for the definite articles used in case of
% consonants and vowels, respectively. Parameters \emph{sym1} and \emph{sym2} are used to 
% handle cases when the reference has to be put between some symbols, e.g. ``('' and ``)''.
%    \begin{macrocode}
%%
\newcount\nev@ind%
\newcount\nev@vege%
\newcount\nev@eppme%
\newcount\nev@az%
%%
\newcommand{\z@aaz}[5]{%
  \begingroup%
  \IfBeginWith{#1}{1}{% if the reference starts with 1,
                      % special care is required
    \StrLen{#1}[\nev@hossz]%
    \nev@ind=\nev@hossz%
    \nev@vege=0%
    \loop% loops while it does not find a digit at the end
         % (in \ref-s, strangely, an \hbox {} appears at the end;
         % this loop was actually written to remove these)
      \StrChar{#1}{\nev@ind}[\nev@kar]%
      \IfSubStr{1234567890}{\nev@kar}{\nev@vege=1}{}\relax%
      \ifnum\nev@vege=0%
        \advance\nev@ind by -1%
    \repeat%
    \StrLeft{#1}{\nev@ind}[\nev@paramuj]% \paramuj will contain the
                                        % ``cleaned'' parameter
    \StrPosition[1]{\nev@paramuj}{.}[\nev@elsopontpozicioja]%
    \StrLen{\nev@paramuj}[\nev@hossz]%
    \nev@eppme=\nev@elsopontpozicioja%
    \advance\nev@eppme by -1%
    \ifnum\nev@elsopontpozicioja=0%
      \StrLeft{\nev@paramuj}{\nev@hossz}[\nev@prefix]%
    \else%
      \StrLeft{\nev@paramuj}{\nev@eppme}[\nev@prefix]%
    \fi%
    \StrLen{\nev@prefix}[\nev@elsohossz]%
    \ifnum\nev@elsohossz=1\relax% 1
      #3%
    \else\ifnum\nev@elsohossz=2\relax% 10
      #2%
    \else\ifnum\nev@elsohossz=3\relax% 100
      #2%
    \else\ifnum\nev@elsohossz=4\relax% 1000
      #3%
    \fi\fi\fi\fi%
  }{%
    \StrChar{#1}{1}[\nev@kar]%
    \nev@az=0%
    \IfSubStr{2346789}{\nev@kar}{% digits that require ``a'';
                                 % this is redundant, but was kept for some reasons
      \nev@az=0\relax%
    }{%
      \IfSubStr{5AEIOUFLMNRSaeiouflmnrs}{\nev@kar}{% digits and letters
                                                   % that require ``az''
        \nev@az=1\relax%
      }{%
        \nev@az=0\relax%
      }%
    }%
    \ifnum\nev@az=1\relax%
      #3%
    \else%
      #2%
    \fi%
  }%
  \ #4#1#5%
  \endgroup%
}%
%%
%    \end{macrocode}
% \end{macro}
%
% \begin{thebibliography}{9}
%   \bibitem{Eijkhout92}
%     Victor Eijkhout,
%     \emph{TeX by Topic. A TeXnician's Reference},
%     Addison-Wesley, Wokingham, England, 1992.
% \end{thebibliography}
%
%\Finale
\endinput