summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/xgreek/xgreek.dtx
blob: 1e71b5df9d6505a4bf67d52defaba17703b9bda9 (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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
%% \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         \~}
%%
%\iffalse
%
% (c) Copyright 2007-2024 Apostolos Syropoulos 
% This program can be redistributed and/or modified under the 
% terms of the LaTeX Project Public License Distributed from 
% http://www.latex-project.org/lppl.txt; either
% version 1.3c of the License, or any later version.
%  
% This work has the LPPL maintenance status `maintained'.
%
% Please report errors or suggestions for improvement to
%
%    Apostolos Syropoulos  (asyropoulos@yahoo.com)
%
%\fi
% \CheckSum{795}
% \iffalse This is a Metacommentxel	
%
%<xgreek, >\ProvidesFile{xgreek.sty}
%<xelistings, >\ProvidesFile{xelistings}
%
%<xgreek, > [2024/01/01 v3.3.0 Package `xgreek.sty']
%<xelistings, > [2022/09/04 v1.0 Package `xelistings.sty']
%
%    \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}
\GetFileInfo{xgreek.drv}
\usepackage{xltxtra}
\usepackage{fullpage}
\begin{document}
%\newopentypefeature{Contextuals}{Alts}{+calt}
\setmainfont[Mapping=tex-text,Script=Greek,
             SmallCapsFeatures={Contextuals=Alternate}]{Universal Modern}
\setmonofont{UM Typewriter}
\setsansfont[Mapping=tex-text]{GFS Neohellenic}
   \DocInput{xgreek.dtx}
\end{document}
%</driver>
%    \end{macrocode}
% \fi
%\StopEventually{}
%\title{Greek Language Support for\\ \XeLaTeX\ and Lua\LaTeX}
%\author{Apostolos Syropoulos\\
%        Xanthi, Greece\\
%        \texttt{asyropoulos@yahoo.com}}
% \date{2009/11/23\\ Last Updated 2024/01/01}
%\maketitle
% \begin{abstract}
% The \textsf{xgreek} package provides rudimentary support for Greek language
% typesetting with \XeLaTeX and Lua\LaTeX. In particular, it provides support for modern 
% Greek (either monotonic or polytonic) and ancient Greek.  
%\end{abstract}
%
%\section{Introduction}
%
% The \textsf{xgreek} package provides rudimentary support for Greek language
% typesetting with \XeLaTeX and Lua\LaTeX. Users will be able to typeset documents in 
% either modern Greek (monotonic or polytonic) or ancient Greek by selecting the appropriate
% package option. The default ``language'' is monotonic Greek.  
%
% Support for Lua\LaTeX\ was provided by Javier Bezos. 
%
% \section{The Source Code of \textsf{xgreek}}
% According to the Unicode standard 
%\begin{center}
%|http://www.unicode.org/Public/UNIDATA/UnicodeData.txt|
%\end{center}
% the uppercase form of the letter GREEK SMALL LETTER EPSILON WITH TONOS is the letter
% GREEK CAPITAL LETTER EPSILON WITH TONOS. According to the grammar of the Greek
% language this is wrong. When text is tranfformed into uppercase, all letters lose 
% accents and when a letter has GREEK DIALYTIKA TONOS, then only the DIALYTIKA remain.
% Thus, the uppercase form of the letter GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS is
% the letter GREEK CAPITAL LETTER IOTA WITH DIALYTIKA. Also, the uppercase form of the letter
% GREEK SMALL LETTER EPSILON WITH TONOS is the letter GREEK CAPITAL LETTER EPSILON. For ancient
% Greek something similar holds---All accents and breathings disappear and only the letters having
% DIALYTIKA keep them. For example, the uppercase form of the letter GREEK SMALL LETTER 
% UPSILON WITH DIALYTIKA AND PERISPOMENI is the letter GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA.
% In addition, for any lowercase letter that has a GREEK YPOGEGRAMMENI the equivalent uppercase letter
% is the one with a PROSGEGRAMMENI. For example, the uppercase form of the letter GREEK SMALL LETTER ETA 
% WITH OXIA AND YPOGEGRAMMENI is the letter GREEK CAPITAL LETTER ETA WITH PROSGEGRAMMENI. However, there is
% one exception: the word GREEK SMALL LETTER ETA WITH PSILI AND OXIA (GREEK SMALL LETTER ETA WITH TONOS
% in Modern Greek), which is the equiavalent of the English word ``or.'' In order not to confuse it with
% the feminine article in the nominative case (i.e., the letter GREEK SMALL LETTER ETA WITH DASIA), 
% this article keeps the accent in an uppercase letters only text. Unfortunately, this feature cannot be
% easily implemented since it would require a rule of the form
%\begin{center}
% ``SPACE'' ``GREEK SMALL LETTER ETA WITH PSILI AND OXIA'' ``SPACE''\\ --->\\ ``SPACE'' ``GREEK CAPITAL LETTER ETA WITH OXIA'' ``SPACE''
%\end{center}
% 
% It is a fact that \LaTeX\ {\em blindly} follows the Unicode standard and so the command |\MakeUppercase| produces wrong output. 
% For this reason, in previous versions of this package, I introduced many pairs of |\uccode| and |\lccode| commands to fix
% this problem. Quite recently, I realize that these commands do not produce the expected result as the new implementation of
% the command |\MakeUppercase| completely ignores these commands. Fortunately, the person who did this re-implementation,
% defined the new command |\DeclareUppercaseMapping| which maps the character code of a lowercase letter to the actual
% uppercase character. The commands that follow implement the grammatical rules of the Greek language except of course the
% rule for the Greek disjunctive conjunction.
%    \begin{macrocode}
%<*xgreek>
\message{Package 'xgreek' version 3.3.0 by Apostolos Syropoulos}
\DeclareUppercaseMapping{"0390}{Ϊ} \DeclareLowercaseMapping{"0390}{ΐ}
\DeclareUppercaseMapping{"03AC}{Α} \DeclareLowercaseMapping{"03AC}{ά}
\DeclareUppercaseMapping{"03AD}{Ε} \DeclareLowercaseMapping{"03AD}{έ}
\DeclareUppercaseMapping{"03AE}{Η} \DeclareLowercaseMapping{"03AE}{ή}
\DeclareUppercaseMapping{"03AF}{Ι} \DeclareLowercaseMapping{"03AF}{ί}
\DeclareUppercaseMapping{"03B0}{Ϋ} \DeclareLowercaseMapping{"03B0}{ΰ}
\DeclareUppercaseMapping{"03CA}{Ϊ} \DeclareLowercaseMapping{"03CA}{ϊ}
\DeclareUppercaseMapping{"03CB}{Ϋ} \DeclareLowercaseMapping{"03CB}{ϋ}
\DeclareUppercaseMapping{"03CC}{Ο} \DeclareLowercaseMapping{"03CC}{ό}
\DeclareUppercaseMapping{"03CD}{Υ} \DeclareLowercaseMapping{"03CD}{ύ}
\DeclareUppercaseMapping{"03CE}{Ω} \DeclareLowercaseMapping{"03CE}{ώ}
\DeclareUppercaseMapping{"1F00}{Α}
\DeclareUppercaseMapping{"1F01}{Α}
\DeclareUppercaseMapping{"1F02}{Α}
\DeclareUppercaseMapping{"1F03}{Α}
\DeclareUppercaseMapping{"1F04}{Α}
\DeclareUppercaseMapping{"1F05}{Α}
\DeclareUppercaseMapping{"1F06}{Α}
\DeclareUppercaseMapping{"1F07}{Α}
\DeclareUppercaseMapping{"1F10}{Ε}
\DeclareUppercaseMapping{"1F11}{Ε}
\DeclareUppercaseMapping{"1F12}{Ε}
\DeclareUppercaseMapping{"1F13}{Ε}
\DeclareUppercaseMapping{"1F14}{Ε}
\DeclareUppercaseMapping{"1F15}{Ε}
\DeclareUppercaseMapping{"1F20}{Η}
\DeclareUppercaseMapping{"1F21}{Η}
\DeclareUppercaseMapping{"1F22}{Η}
\DeclareUppercaseMapping{"1F23}{Η}
\DeclareUppercaseMapping{"1F24}{Η}
\DeclareUppercaseMapping{"1F25}{Η}
\DeclareUppercaseMapping{"1F26}{Η}
\DeclareUppercaseMapping{"1F27}{Η}
\DeclareUppercaseMapping{"1F30}{Ι}
\DeclareUppercaseMapping{"1F31}{Ι}
\DeclareUppercaseMapping{"1F32}{Ι}
\DeclareUppercaseMapping{"1F33}{Ι}
\DeclareUppercaseMapping{"1F34}{Ι}
\DeclareUppercaseMapping{"1F35}{Ι}
\DeclareUppercaseMapping{"1F36}{Ι}
\DeclareUppercaseMapping{"1F37}{Ι}
\DeclareUppercaseMapping{"1F40}{Ο}
\DeclareUppercaseMapping{"1F41}{Ο}
\DeclareUppercaseMapping{"1F42}{Ο}
\DeclareUppercaseMapping{"1F43}{Ο}
\DeclareUppercaseMapping{"1F44}{Ο}
\DeclareUppercaseMapping{"1F45}{Ο}
\DeclareUppercaseMapping{"1F50}{Υ}
\DeclareUppercaseMapping{"1F51}{Υ}
\DeclareUppercaseMapping{"1F52}{Υ}
\DeclareUppercaseMapping{"1F53}{Υ}
\DeclareUppercaseMapping{"1F54}{Υ}
\DeclareUppercaseMapping{"1F55}{Υ}
\DeclareUppercaseMapping{"1F56}{Υ}
\DeclareUppercaseMapping{"1F57}{Υ}
\DeclareUppercaseMapping{"1F60}{Ω}
\DeclareUppercaseMapping{"1F61}{Ω}
\DeclareUppercaseMapping{"1F62}{Ω}
\DeclareUppercaseMapping{"1F63}{Ω}
\DeclareUppercaseMapping{"1F64}{Ω}
\DeclareUppercaseMapping{"1F65}{Ω}
\DeclareUppercaseMapping{"1F66}{Ω}
\DeclareUppercaseMapping{"1F67}{Ω}
\DeclareUppercaseMapping{"1F70}{Α} \DeclareUppercaseMapping{"1F71}{Α}
\DeclareUppercaseMapping{"1F72}{Ε} \DeclareUppercaseMapping{"1F73}{Ε}
\DeclareUppercaseMapping{"1F74}{Η} \DeclareUppercaseMapping{"1F75}{Η}
\DeclareUppercaseMapping{"1F76}{Ι} \DeclareUppercaseMapping{"1F77}{Ι}
\DeclareUppercaseMapping{"1F78}{Ο} \DeclareUppercaseMapping{"1F79}{Ο}
\DeclareUppercaseMapping{"1F7A}{Υ} \DeclareUppercaseMapping{"1F7B}{Υ}
\DeclareUppercaseMapping{"1F7C}{Ω} \DeclareUppercaseMapping{"1F7D}{Ω}
\DeclareUppercaseMapping{"1F80}{ᾼ}
\DeclareUppercaseMapping{"1F81}{ᾼ}
\DeclareUppercaseMapping{"1F82}{ᾼ}
\DeclareUppercaseMapping{"1F83}{ᾼ}
\DeclareUppercaseMapping{"1F84}{ᾼ}
\DeclareUppercaseMapping{"1F85}{ᾼ}
\DeclareUppercaseMapping{"1F86}{ᾼ}
\DeclareUppercaseMapping{"1F87}{ᾼ}
\DeclareUppercaseMapping{"1F90}{ῌ}
\DeclareUppercaseMapping{"1F91}{ῌ}
\DeclareUppercaseMapping{"1F92}{ῌ}
\DeclareUppercaseMapping{"1F93}{ῌ}
\DeclareUppercaseMapping{"1F94}{ῌ}
\DeclareUppercaseMapping{"1F95}{ῌ}
\DeclareUppercaseMapping{"1F96}{ῌ}
\DeclareUppercaseMapping{"1F97}{ῌ}
\DeclareUppercaseMapping{"1FA0}{ῼ}
\DeclareUppercaseMapping{"1FA1}{ῼ}
\DeclareUppercaseMapping{"1FA2}{ῼ}
\DeclareUppercaseMapping{"1FA3}{ῼ}
\DeclareUppercaseMapping{"1FA4}{ῼ}
\DeclareUppercaseMapping{"1FA5}{ῼ}
\DeclareUppercaseMapping{"1FA6}{ῼ}
\DeclareUppercaseMapping{"1FA7}{ῼ}
\DeclareUppercaseMapping{"1FB2}{ᾼ}
\DeclareUppercaseMapping{"1FB3}{ᾼ}
\DeclareUppercaseMapping{"1FB4}{ᾼ}
\DeclareUppercaseMapping{"1FB6}{Α}
\DeclareUppercaseMapping{"1FB7}{ᾼ}
\DeclareUppercaseMapping{"1FC2}{ῌ}
\DeclareUppercaseMapping{"1FC3}{ῌ}
\DeclareUppercaseMapping{"1FC4}{ῌ}
\DeclareUppercaseMapping{"1FC6}{Η}
\DeclareUppercaseMapping{"1FC7}{ῌ}
\DeclareUppercaseMapping{"1FD2}{Ϊ}
\DeclareUppercaseMapping{"1FD3}{Ϊ}
\DeclareUppercaseMapping{"1FD6}{Ι}
\DeclareUppercaseMapping{"1FD7}{Ϊ}
\DeclareUppercaseMapping{"1FE2}{Ϋ}
\DeclareUppercaseMapping{"1FE3}{Ϋ}
\DeclareUppercaseMapping{"1FE4}{Ρ}
\DeclareUppercaseMapping{"1FE5}{Ρ}
\DeclareUppercaseMapping{"1FE6}{Υ}
\DeclareUppercaseMapping{"1FE7}{Ϋ}
\DeclareUppercaseMapping{"1FF2}{ῼ}
\DeclareUppercaseMapping{"1FF3}{ῼ}
\DeclareUppercaseMapping{"1FF4}{ῼ}
\DeclareUppercaseMapping{"1FF6}{Ω}
\DeclareUppercaseMapping{"1FF7}{ῼ}
%    \end{macrocode}
% Next I define the various strings that correspond to the standard \LaTeX\ captions.
% I first define the strings for monotonic Greek. 
%    \begin{macrocode}
\def\prefacename{Πρόλογος}%
\def\refname{Αναφορές}%
\def\abstractname{Περίληψη}%
\def\bibname{Βιβλιογραφία}%
\def\chaptername{Κεφάλαιο}%
\def\appendixname{Παράρτημα}%
\def\contentsname{Περιεχόμενα}%
\def\listfigurename{Κατάλογος σχημάτων}%
\def\listtablename{Κατάλογος πινάκων}%
\def\indexname{Ευρετήριο}%
\def\figurename{Σχήμα}%
\def\tablename{Πίνακας}%
\def\partname{Μέρος}%
\def\enclname{Συνημμένα}%
\def\ccname{Κοινοποίηση}%
\def\headtoname{Προς}%
\def\pagename{Σελίδα}%
\def\seename{βλέπε}%
\def\alsoname{βλέπε επίσης}%
\def\proofname{Απόδειξη}%
\def\glossaryname{Γλωσσάρι}%
%    \end{macrocode}
% Macro |\polytonicn@mes| is invoked when polytonic Greek is the main language of the document.
%    \begin{macrocode} 
\def\polytonicn@mes{%
  \def\refname{Ἀναφορὲς}%
  \def\indexname{Εὑρετήριο}%
  \def\figurename{Σχῆμα}%
  \def\headtoname{Πρὸς}%
  \def\alsoname{βλέπε ἐπίσης}%
  \def\proofname{Ἀπόδειξη}%
}
%    \end{macrocode}
% Macro |\@ncientn@mes| is invoked when ancient Greek is the main language of the document (Dinitrios Filippou
% spotted a couple of spelling errors in the list below).
%    \begin{macrocode} 
\def\@ncientn@mes{%
  \def\prefacename{Προοίμιον}%
  \def\abstractname{Περίληψις}%
  \def\bibname{Βιβλιογραφία}%
  \def\chaptername{Κεφάλαιον}%
  \def\appendixname{Παράρτημα}%
  \def\contentsname{Περιεχόμενα}%
  \def\listfigurename{Κατάλογος σχημάτων}%
  \def\listtablename{Κατάλογος πινάκων}%
  \def\indexname{Εὑρετήριον}%
  \def\tablename{Πίναξ}%
  \def\partname{Μέρος}%
  \def\enclname{Συνημμένως}%
  \def\ccname{Κοινοποίησις}%
  \def\headtoname{Πρὸς}%
  \def\pagename{Σελὶς}%
  \def\seename{ὅρα}%
  \def\alsoname{ὅρα ὡσαύτως}%
  \def\proofname{Ἀπόδειξις}%
  \def\glossaryname{Γλωσσάριον}%
  \def\refname{Ἀναφοραὶ}%
  \def\figurename{Σχῆμα}%
  \def\headtoname{Πρὸς}%
}
%    \end{macrocode}
% I redefine |\today| so as to produce dates in Greek. The
% names of months are defined by the macro |\gr@month|. 
%    \begin{macrocode}
\def\gr@month{%
  \ifcase\month\or Ιανουαρίου\or Φεβρουαρίου\or Μαρτίου\or Απριλίου\or
    Μαΐου\or Ιουνίου\or Ιουλίου\or Αυγούστου\or
     Σεπτεμβρίου\or Οκτωβρίου\or Νοεμβρίου\or Δεκεμβρίου\fi}
\def\today{\number\day \space \gr@month\space \number\year}
%    \end{macrocode}
% When either polytonic Greek or ancient Greek is the main language of the document,
% then the macro |\gr@c@month| becomes active.  
%    \begin{macrocode}
\def\gr@c@month{%
  \ifcase\month\or Ἰανουαρίου\or Φεβρουαρίου\or Μαρτίου\or Ἀπριλίου\or 
   Μαΐου\or Ἰουνίου\or Ἰουλίου\or Αὐγούστου\or Σεπτεμβρίου\or
  Ὀκτωβρίου\or Νοεμβρίου\or Δεκεμβρίου\fi}
%    \end{macrocode}
% Next, I define a few macros that allow one to access characters
% that are not usually easily accessible from the keyboard (e.g., the sampi or the
% koppa symbol). The list includes a command for the Unicode symbol GREEK ANO TELEIA,
% which, in some systems, is confused with MIDDLE DOT. The use of command |\numer@lsign|
% will be explained later.
%    \begin{macrocode}
\def\anwtonos{ʹ} %GREEK NUMERAl SIGN
\let\numer@lsign\anwtonos
\def\katwtonos{͵} %GREEK LOWER NUMERAL SIGN
\def\koppa{\char"03DF\relax}
\def\sampi{\char"03E1\relax}
\def\Digamma{\char"03DC\relax}
\def\ddigamma{\char"03DD\relax}
\def\anoteleia{\char"0387\relax}
\def\euro{\char"20AC\relax}
\def\permill{\char"2030\relax}
%    \end{macrocode}
% Many users prefer the use of the letters sigma and tau instead of the stigma symbol in
% Greek numerals, therefore, by default the |\stigma| command expands to ``στ''. 
%    \begin{macrocode}
\def\stigma{στ\relax}
%    \end{macrocode}
% The following commands take care of the basic rules of typography. Note that the first command
% changes the way space is added after punctuation symbols and the last two commands force \LaTeX\
% to add indentation space to the first paragraph after a header. Since a number of users need, for 
% their own reasons, to be able to disable this particular feature I have introduced a new package
% option, namely |noindentfirst|, which restores the default behavior. In order to be able
% to do this I need the original value of the boolean variable |\@afterindentfalse|.
%    \begin{macrocode}
\frenchspacing
\let\@saveafterindentfalse\@afterindentfalse
\let\@afterindentfalse\@afterindenttrue
\@afterindenttrue
%    \end{macrocode}
% Lua\LaTeX\ and \XeLaTeX\ have different ways to load hyphenation patterns. Package 
% \textsf{luahyphenrules} by Javier Bezos facilitates this process for people who
% want to use Lua\LaTeX\ and the ``traditional'' way to load hyphenation patterns. 
% To ensure proper inclusion of LuaTeX staff, I use the following ``idiom'':
% \begin{center}
% |\ifx\directlua\undefined |\texttt{\textit{non Lua\LaTeX\ code}}|\else |%
% \texttt{\textit{Lua\LaTeX\ code}}|\fi|
% \end{center} 
%    \begin{macrocode}
\ifx\directlua\undefined\else\RequirePackage{luahyphenrules}\fi
%    \end{macrocode}
% The code that follows specifies which hyphenation patterns will be active. The \XeLaTeX\ code
% is quite standard and depends on the \textsf{babel} pattern loading mechanism, while the
% Lua\LaTeX\ code uses the |\HyphenRules| macro, which has essentially the functionality 
% of the |\selectlanguage| macro.
%    \begin{macrocode}
\DeclareOption{monogreek}{%
   \ifx\directlua\undefined%
   \language\l@monogreek\else\HyphenRules{monogreek}\fi%
}
\DeclareOption{polygreek}{%
   \ifx\directlua\undefined%
   \language\l@polygreek\else\HyphenRules{polygreek}\fi%
   \polytonicn@mes%
   \let\gr@month\gr@c@month%
}
\DeclareOption{ancientgreek}{%
   \ifx\directlua\undefined%
   \language\l@ancientgreek\else\HyphenRules{ancientgreek}\fi%
   \@ncientn@mes%
   \let\gr@month\gr@c@month%
}
%    \end{macrocode}
% If a user wants to use the stigma symbol in Greek numerals, she should use the
% |stigma| option.
%    \begin{macrocode}
\DeclareOption{stigma}{%
   \def\stigma{\char"03DB\relax}
}
%    \end{macrocode}
% As noted above, the new option |noindentfirst| restores the default \LaTeX\ behavior of adding no 
% indentation to the first paragraph after any header. 
%    \begin{macrocode}
\DeclareOption{noindentfirst}{%
   \let\@afterindentfalse\@saveafterindentfalse
}
%    \end{macrocode}
% Nowadays it is customary in Greece to use Greek numerals without the GREEK NUMERAL SIGN at the end
% of a numeral. Thus, the |nonumeralsign| option disables the typesetting of the GREEK NUMERAL SIGN
% at the end of Greek numerals. 
%    \begin{macrocode}
\DeclareOption{nonumeralsign}{%
   \let\numer@lsign\relax
}
%    \end{macrocode}
%  Package \textsf{listings} does not work properly with UTF-8 encoded files. So this
% option should be used whenever one wants to use this package and see Greek text come out
% correctly. In version 3.1.0 of this package, I included code that modified the source code of 
% package \textsf{listings}. However, this decision was wrong. In particular, when one did not use 
% the corresponding \texttt{listings} option, processing of the input file stopped with an error message 
% about a text line that contains an invalid character. So the best way to solve this problem was to move 
% the code to a different file and create essentially a new package. This package is automatically loaded 
% when the user pecifies the \texttt{listings} option. To make this possible, I used a boolean 
% variable.
%    \begin{macrocode}
\newif\if@mylistings
\@mylistingsfalse
\DeclareOption{listings}{\@mylistingstrue}
%    \end{macrocode}
% By default the |monogreek| option is activated. 
%    \begin{macrocode}
\ExecuteOptions{monogreek}
\ProcessOptions
%    \end{macrocode}
% If the user has enabled the |listings| option, then the package loads the package \textsf{xelistings}.
%    \begin{macrocode}
\if@mylistings
\RequirePackage{xelistings}
\fi
%    \end{macrocode}
% Now I am going to define the macros that typeset alphabetic Greek numerals. The code 
% is borrowed from the Greek option for the babel package.
%  \begin{macro}{\gr@ill@value}
%    When the argument of |\greeknumeral| has a value outside of the
%    acceptable bounds ($0 < x < 999999$) a warning will be issued
%    (and nothing will be printed).
%    \begin{macrocode}
\def\gr@ill@value#1{%
  \PackageWarning{xgreek}{Illegal value (#1) for greeknumeral}}
%    \end{macrocode}
%  \end{macro}
%  \begin{macro}{\anw@true}
%  \begin{macro}{\anw@false}
%  \begin{macro}{\anw@print}
%    When a large number with three \emph{trailing} zeros is to be
%    printed those zeros \emph{and} the numeric mark need to be
%    discarded. As each `digit' is processed by a separate macro
%    \emph{and} because the processing needs to be expandable we need
%    some helper macros that help remember to \emph{not} print the
%    numeric mark (|\numer@lsign|).
%
%    The command |\anw@false| switches the printing of the numeric
%    mark off by making |\anw@print| expand to nothing. The command
%    |\anw@true| (re)enables the printing of the numeric marc. These
%    macro's need to be robust in order to prevent improper expansion
%    during writing to files or during |\uppercase|.
%    \begin{macrocode}
\DeclareRobustCommand\anw@false{%
  \DeclareRobustCommand\anw@print{}}
\DeclareRobustCommand\anw@true{%
  \DeclareRobustCommand\anw@print{\numer@lsign}}
\anw@true
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\@greeknumeral}
%    This command is used to get Greek numerals. The command uses
%    |\numer@lsign| to get the NUMERAL SIGN. Obviously, when the
%    user has specified the \texttt{no\-numeral\-sign} option, then numeral
%    comes out without the trailing NUMERAL SIGN. However, when a user
%    wants to typeset a Greek numeral, the numeral must come out correctly,
%    regardless of what appears in headers, etc. And that is exactly the
%    reason why this command is inaccessible to users.
%    The command |\@greeknumeral| needs to be \emph{fully} expandable
%    in order to get the right information in auxiliary
%    files. Therefore we use a big |\if|-construction to check the
%    value of the argument and start the parsing at the right level.
%    \begin{macrocode}
\def\@greeknumeral#1{%
%    \end{macrocode}
%    If the value is negative or zero nothing is printed and a warning
%    is issued.
%    \begin{macrocode}
  \ifnum#1<\@ne\space\gr@ill@value{#1}%
  \else
    \ifnum#1<10\expandafter\gr@num@i\number#1%
    \else
      \ifnum#1<100\expandafter\gr@num@ii\number#1%
      \else
%    \end{macrocode}
%    The available shorthands for 1.000 (|\@m|) and 10.000
%    (|\@M|) are used to save a few tokens.
%    \begin{macrocode}
        \ifnum#1<\@m\expandafter\gr@num@iii\number#1%
        \else
          \ifnum#1<\@M\expandafter\gr@num@iv\number#1%
          \else
            \ifnum#1<100000\expandafter\gr@num@v\number#1%
            \else
              \ifnum#1<1000000\expandafter\gr@num@vi\number#1%
              \else
%    \end{macrocode}
%    If the value is too large, nothing is printed and a warning
%    is issued.
%    \begin{macrocode}
                \space\gr@ill@value{#1}%
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%  \end{macro}
%
%    What is left to make complete the definition of command |\greeknumeral| is a set of macros to produce
%    the various digits.
%  \begin{macro}{\gr@num@i}
%  \begin{macro}{\gr@num@ii}
%  \begin{macro}{\gr@num@iii}
%    As there is no ``digit'' representing $0$ in this system, the zeros
%    are simply discarded. When there is a large number with three
%    \emph{trailing} zeros also the numeric mark is discarded. 
%    Therefore these macros need to pass the information to each other
%    about the (non-)translation of a zero.
%    \begin{macrocode}
\def\gr@num@i#1{%
  \ifcase#1\or α\or β\or γ\or δ\or ε\or \stigma\or ζ\or η\or θ\fi
  \ifnum#1=\z@\else\anw@true\fi\anw@print}
\def\gr@num@ii#1{%
  \ifcase#1\or ι\or κ\or λ\or μ\or ν\or ξ\or ο\or π\or \koppa\fi
  \ifnum#1=\z@\else\anw@true\fi\gr@num@i}
\def\gr@num@iii#1{%
  \ifcase#1\or ρ\or σ\or τ\or υ\or φ\or χ\or ψ\or ω\or \sampi\fi
  \ifnum#1=\z@\anw@false\else\anw@true\fi\gr@num@ii}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\gr@num@iv}
%  \begin{macro}{\gr@num@v}
%  \begin{macro}{\gr@num@vi}
%    The first three ``digits'' always have the numeric mark, except
%    when one is discarded because it's value is zero.
%    \begin{macrocode}
\def\gr@num@iv#1{%
  \ifnum#1=\z@\else\katwtonos\fi
  \ifcase#1\or α\or β\or γ\or δ\or ε\or \stigma\or ζ\or η\or θ\fi
  \gr@num@iii}
\def\gr@num@v#1{%
  \ifnum#1=\z@\else\katwtonos\fi
  \ifcase#1\or ι\or κ\or λ\or μ\or ν\or ξ\or ο\or π\or \koppa\fi
  \gr@num@iv}
\def\gr@num@vi#1{%
  \katwtonos
  \ifcase#1\or ρ\or σ\or τ\or υ\or φ\or χ\or ψ\or ω\or \sampi\fi
  \gr@num@v}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \begin{macro}{\@Greeknumeral}
%    The command |\@Greeknumeral| prints uppercase Greek numerals. 
%    The parsing is performed by the macro |\@greeknumeral|. The printing
%    of the NUMERAL SIGN depends on the value of |\numer@lsign|.
%    \begin{macrocode}
\def\@Greeknumeral#1{%
  \expandafter\MakeUppercase\expandafter{\@greeknumeral{#1}}}
%    \end{macrocode}
%  \end{macro}
%  \begin{macro}{\greeknumeral}
%   This command prints lowercase Greek numerals and the NUMERAL SIGN
%   is always printed.
%    \begin{macrocode}
\def\greeknumeral#1{%
  \let\@numer@lsign\numer@lsign%
  \let\numer@lsign\anwtonos%
  \@greeknumeral{#1}
  \let\numer@lsign\@numer@lsign}
%    \end{macrocode}
%  \end{macro}
%  \begin{macro}{\Greeknumeral}
%   This command prints uppercase Greek numerals and the NUMERAL SIGN
%   is always printed.
%    \begin{macrocode}
\def\Greeknumeral#1{%
  \let\@numer@lsign\numer@lsign%
  \let\numer@lsign\anwtonos%
  \@Greeknumeral{#1}
  \let\numer@lsign\@numer@lsign}
%    \end{macrocode}
%  \end{macro}
%
% The alphabetic numbering system is not the only numbering system employed by Greeks.
% In fact, Greeks used various systems that are now known as {\em acrophonic} numbering
% systems. Many scholars are familiar with the acrophonic Attic numbering system and the
% the command |\atticnum| can be used to generate acrophonic Attic numerals.  
% The acrophonic Attic numbering system, like the Roman one, employs
% letters to denote important numbers. Multiple occurrence of a letter denote
% a multiple of the ``important'' number, e.g., the letter Ι denotes 1, so
% ΙΙΙ denotes 3. Here are the basic digits used in the acrophonic Attic numbering
% system:
% \begin{itemize}
%  \item Ι denotes the number one (1)
%  \item Π denotes the number five (5)
%  \item Δ denotes the number ten (10)
%  \item Η denotes the number one hundred (100)
%  \item Χ denotes the number one thousand (1000)
%  \item Μ denotes the number ten thousands (10000)
%\end{itemize}
% Moreover,  the letters Δ, Η, Χ, and Μ under the letter ^^^^^^010143 (a form of Π)
% denote five times their original value. In particular, the symbol ^^^^^10144, denotes 
% the number 50, the symbol ^^^^^10145 denotes the number 500, the symbol ^^^^^10146
% denotes the number 5000, and the symbol ^^^^^10147 denotes the number 50,000. It 
% must be noted that the numbering system does not provide negative numerals or a symbol for
% zero. 
%\begin{macro}{\@@atticnum}            
% Now, let me definite the macro 
% |\@@atticnum|. This macro uses one integer variable (or counter in 
% \TeX's jargon.)
%    \begin{macrocode}
\newcount\@attic@num
%    \end{macrocode}
% The macro |\@@atticnum| is also defined as a robust command.
%    \begin{macrocode}
\DeclareRobustCommand*{\@@atticnum}[1]{%
%    \end{macrocode}
% After assigning to variable |\@attic@num| the value of the macro's argument, 
% we make sure that the argument is in the expected range, i.e., it is greater
% than zero, and less or equal to $249999$.  In case it is not, it simply 
% produces a |\space|, warns the user about it and quits. Although, the
% |\atticnum| macro is capable to produce an Athenian numeral for even greater
% intergers, the following argument by Claudio Beccari convinced me to place
% this upper limit:
% \begin{quote} 
% According to psychological perception studies (that ancient Athenians
% and Romans perfectly knew without needing to study Freud and Jung)
% living beings (which includes at least all vertebrates, not only
% humans) can perceive up to four randomly set objects of the same kind   
% without the need of counting, the latter activity being a specific
% acquired ability of human kind; the biquinary numbering notation
% used by the Athenians and the Romans exploits this natural
% characteristic of human beings.
% \end{quote}
%    \begin{macrocode}
        \@attic@num#1\relax
        \ifnum\@attic@num<\@ne%
          \space%
          \PackageWarning{xgreek}{%
          Illegal value (\the\@attic@num) for acrophonic 
          Attic numeral}%
        \else\ifnum\@attic@num>249999%
          \space%
          \PackageWarning{xgreek}{%
          Value too large (\the\@attic@num) for acrophonic 
          Attic numeral}%
        \else
%    \end{macrocode}
% Having done all the necessary checks, it is possible to proceed with the actual
% computation. If the number is greater than $49999$, then it certainly
% has at least one ^^^^^10147 ``digit''. The macro finds all such digits by continuously
% subtracting $50000$ from |\@attic@num|, until |\@attic@num| becomes less than
% $50000$. 
%    \begin{macrocode}
            \@whilenum\@attic@num>49999\do{%
               ^^^^^^010147\advance\@attic@num-50000}%
%    \end{macrocode}
% Next the macro checks for tens of thousands.
%    \begin{macrocode}
            \@whilenum\@attic@num>9999\do{%
               M\advance\@attic@num-\@M}%
%    \end{macrocode}
% Since a number can have only one ^^^^^10146 ``digit'' (equivalent to 5000), it 
% is easy to check whether is should have one and produce the corresponding numeral when
% it does have one.
%    \begin{macrocode}
            \ifnum\@attic@num>4999%
               ^^^^^^010146\advance\@attic@num-5000%
            \fi\relax
%    \end{macrocode}
% The macro should also check for thousands, the same way it checked for tens of thousands.
%    \begin{macrocode}
            \@whilenum\@attic@num>999\do{%
               Χ\advance\@attic@num-\@m}%
%    \end{macrocode} 
% Since a numeral can have at most one ^^^^^10145 ``digit'' (equivalent to 500), this should be
% handled the way the macro handled the case of the five thousands ``digit''.
%    \begin{macrocode}
            \ifnum\@attic@num>499%
               ^^^^^^010145\advance\@attic@num-500%
            \fi\relax
%    \end{macrocode}
% It is time to check hundreds, which follow the same pattern as thousands.
%    \begin{macrocode}
            \@whilenum\@attic@num>99\do{%
               Η\advance\@attic@num-100}%
%    \end{macrocode}
% A numeral can have only one ^^^^^10144 ``digit'' (equivalent to 50).
%    \begin{macrocode} 
            \ifnum\@attic@num>49%
               ^^^^^^010144\advance\@attic@num-50%
            \fi\relax
%    \end{macrocode}
% The macro now checks now for tens digit.
%    \begin{macrocode}         
            \@whilenum\@attic@num>9\do{%
               Δ\advance\@attic@num by-10}%
%    \end{macrocode}
% Finally, it has to check for fives and the digits 1, 2, 3, and 4.
%    \begin{macrocode}
            \@whilenum\@attic@num>4\do{%
               Π\advance\@attic@num-5}%
            \ifcase\@attic@num\or Ι\or ΙΙ\or ΙΙΙ\or ΙΙΙΙ\fi%
   \fi\fi}
%    \end{macrocode}
%\end{macro}
% 
%\begin{macro}{\@atticnum}
% The command |\@atticnum| has one argument, which
% is a counter. It calls the command |\@@atticnum| to process the value of
% the counter.
%    \begin{macrocode}
\def\@atticnum#1{%
     \expandafter\@@atticnum\expandafter{\the#1}}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\atticnum}
% The command |\atticnum| is a wrapper that declares
% a new counter in a local scope, assigns to it the value of the argument of the command
% and calls the macro |\@atticnum|. This way the command can process correctly
% either a number or a counter. 
%    \begin{macrocode}
\def\atticnum#1{%
     \@attic@num#1\relax
     \@atticnum{\@attic@num}}
%    \end{macrocode}
%\end{macro}
%
%  \begin{macro}{\greek@alph}
%  \begin{macro}{\greek@Alph}
% Here I redefine the macros |\@alph| and |\@Alph|. First, I define some placeholders
%    \begin{macrocode}
\let\latin@alph\@alph
\let\latin@Alph\@Alph
%    \end{macrocode}
%    Then I define the Greek versions; the additional |\expandafter|s
%    are needed in order to make sure the table of contents will be
%    correct (e.g., when there are appendices). 
%    \begin{macrocode}
\def\greek@alph#1{\expandafter\@greeknumeral\expandafter{\the#1}}
\def\greek@Alph#1{\expandafter\@Greeknumeral\expandafter{\the#1}}
%    \end{macrocode}
% By default, Greek alphabetic numerals instead of Latin numerals are used to enumerate items in an
% enumeration environment.
%    \begin{macrocode}
  \let\@alph\greek@alph
  \let\@Alph\greek@Alph
%    \end{macrocode}
% If for some reason, one needs to have the Latin numerals back, then she has to invoke command
% |\nogreekalph|. And if she wants to switch back, then she has to use the |\greekalph|
% command:
%    \begin{macrocode}   
\def\nogreekalph{%
  \let\@alph\latin@alph
  \let\@Alph\latin@Alph}
\def\greekalph{%
  \let\@alph\greek@alph
  \let\@Alph\greek@Alph}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
%  \begin{macro}{\setlanguage}
% We provide the |\setlanguage| command which 
% activates the hypehnation patterns of some other language. It is similar
% to babel's |\selectlanguage|, but we opted to use a new name to avoid possible name conflicts. 
% Valid arguments include |monogreek|, |polygreek|, |ancientgreek|, and |american|. As was noted
% previously, package \textsf{luahyphenrules} provides the command |\HyphenRules| which has exactly
% the same functionality as this command. So when using Lua\LaTeX\ users will actually use the
% |\HyphenRules| command.
%    \begin{macrocode}
\ifx\directlua\undefined%
  \def\setlanguage#1{%
     \expandafter\ifx\csname l@#1\endcsname\relax%
     \typeout{^^J Error: No hyphenation pattern for}%
     \typeout{ language #1 are loaded,}%
     \typeout{ default hyphenation patterns are used.^^J}%
     \language=0%
     \else\language=\csname l@#1\endcsname\fi}
\else
  \let\setlanguage\HyphenRules
\fi
%    \end{macrocode}
%  \end{macro}
%    The macros |\grtoday| and |\Grtoday| produces the current date, only that the
%    month and the day are shown as Greek numerals instead of Arabic
%    as it is usually the case. In addition, the two commands differ in that the
%    later produces the Greek numerals in uppercase.
%    \begin{macrocode}
\def\grtoday{%
  \expandafter\greeknumeral\expandafter{\the\day}\space
  \gr@c@month\space
  \expandafter\greeknumeral\expandafter{\the\year}}
\def\Grtoday{%
  \expandafter\Greeknumeral\expandafter{\the\day}\space
  \gr@c@month\space
  \expandafter\Greeknumeral\expandafter{\the\year}}
%</xgreek>
%    \end{macrocode}
% \section{The Source Code of \textsf{xelistings}}
%
% If the user has enabled the |listings| option, then the package loads the rudimentary package
% \textsf{xelistings}. This package loads the \textsf{listings} package and makes accessible to
% it all characters in the range 128--255 plus all Greek letters that belong to the 
% Greek and Coptic Unicode block. This is achieved by redefining the command |\lst@DefEC|.
%    \begin{macrocode}
%<*xelistings>
\RequirePackage{listings}
\lstset{inputencoding=utf8}
\lst@InputCatcodes
\gdef\lst@DefEC{%
 \lst@CCECUse \lst@ProcessLetter
  ^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f%
  ^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f%
  ^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af%
  ^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf%
  ^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf%
  ^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df%
  ^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef%
  ^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff%
  ^^^^0396^^^^0388^^^^0389^^^^038a^^^^038c% <--- Begin of Greek Letters
  ^^^^038e^^^^038f^^^^0390^^^^0391^^^^0392%
  ^^^^0393^^^^0394^^^^0395^^^^0396^^^^0397%
  ^^^^0398^^^^0399^^^^039a^^^^039b^^^^039c%
  ^^^^039d^^^^039e^^^^039f^^^^03a0^^^^03a1%
  ^^^^03a3^^^^03a4^^^^03a5^^^^03a6^^^^03a7%
  ^^^^03a8^^^^03a9^^^^03aa^^^^03ab^^^^03ac%
  ^^^^03ad^^^^03ae^^^^03af^^^^03b0^^^^03b1%
  ^^^^03b2^^^^03b3^^^^03b4^^^^03b5^^^^03b6%
  ^^^^03b7^^^^03b8^^^^03b9^^^^03ba^^^^03bb%
  ^^^^03bc^^^^03bd^^^^03be^^^^03bf^^^^03c0%
  ^^^^03c1^^^^03c2^^^^03c3^^^^03c4^^^^03c5%
  ^^^^03c6^^^^03c7^^^^03c8^^^^03c9^^^^03ca%
  ^^^^03cb^^^^03cc^^^^03cd^^^^03ce% <--- End of Greek Letters
  ^^00}%
\lst@RestoreCatcodes
%</xelistings>
%    \end{macrocode} 
% \Finale