summaryrefslogtreecommitdiff
path: root/macros/plain/contrib/timetable/timetable.tex
blob: e0c881b852822afbb497d90c77b3e14aaf9a5a46 (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
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
%% timetable.tex - TeX macro for generating timetables.        version 1.0
%% Jiri VERUNEK                                                4. 11. 2001
%% http://verunek.oceany.cz
%% verunek@vol.cz, jiri.verunek@seznam.cz
%%
%%
%% DESCRIPTION
%%   timetable.tex is a TeX macro for generating timetables. It uses
%%   plain format commands. It excels in extremelely high configurability,
%%   nice appearance and simple input. It supports alternating subjects
%%   in dependence on odd and even week. Macro has radix sort mechanism
%%   so the order of subjects in input is irrelevant.
%%   Note that this macro is distributed under the GNU General Public Licence.
%%
%% SYNOPSIS
%%   \timetable[OPTIONS]{SUBJECTS}
%%
%% SUBJECTS
%%   Each subject has following structure
%%     <day>:<subject type>:<beginning>-<duration>=<subjectname>-<location>
%%
%%   <day>
%%     consist of the first two chars of the day (MO,TU,WE,TH,FR)
%%
%%   <subject type>
%%     is one of these OL, L, EL, OP, P, EP.
%%     L means lecture, P - practice, O - odd week and E - even week.
%%
%%   <beginning>
%%     is a number of the teaching hour in which the subject begins.
%%
%%   <duration>
%%     is a number representing the subject duration in the teaching hours
%%
%%   Subjects are separated by commas without spaces. Note the next paragraph.
%%
%% OPTIONS
%%   Options are separated by commas without spaces. The whole block
%%   of options must be enclosed by brackets. All must be placed on
%%   the one line. If you wish to place it on a several lines you will
%%   had to use per cent char `%' on the end of each line!
%%
%%   tablewidth=<DIMENSION>
%%     Table will be stretched into this dimension. It will only enlarge
%%     the distance between vertical lines. No font transformation
%%     will be done.
%%
%%   heading=<text>
%%     This text will be typed in the left upper edge of the table.
%%
%%   strut=height<DIMENSION> depth<DIMENSION>
%%     This invisible prop is inserted into each subject row to enlarge
%%     the height of that row.
%%     Default value is `height1em depth.35em'.
%%
%%   forcehrules
%%     Normally each subject is rounded by lines and no other lines are
%%     drown between the subjects. Using of this option will force
%%     drawing horizontal lines between the days.
%%
%%   forcevrules
%%     Normally each subject is rounded by lines and no other lines are
%%     drown between the subjects. Using of this option will force
%%     drawing verical lines between the teaching hours. No subject will be
%%     naturally crossed out.
%%
%%   environment=<environment>
%%     This does a lot of work. It changes the fonts, names of the day, etc.
%%     So you needn't use some other options to adjust texts to your language.
%%     Send me e-mail if you wish to add your environment.
%%     Supported environment:
%%       czech
%%       slovak
%%
%%   headingfont=<fontname>
%%     This option sets a font in which will be typed the heading text.
%%     Default value for absent environment option is `cmb10'.
%%
%%   columnheadingfont=<fontname>
%%     This option sets a font in which are typed the numbers
%%     of the teaching hours.
%%     Default value for absent environment option is `cmb10'.
%%
%%   rowheadingfont=<fontname>
%%     This option sets a font in which are typed the names of the days
%%     and the `from' and the `to' text.
%%     Default value for absent environment option is `cmb10'.
%%
%%   Lsubjectnamefont=<fontname>
%%     This option sets a font in which is typed the name of the lecture.
%%     Default value for absent environment option is `cmss10'.
%%
%%   Llocationfont=<fontname>
%%     This option sets a font in which are typed the names of the rooms
%%     in which is that lecture taught.
%%     Default value for absent environment option is `cmssi10'.
%%
%%   Psubjectnamefont=<fontname>
%%     This option sets a font in which is typed the name of the practice.
%%     Default value for absent environment option is `cmr10'.
%%
%%   Plocationfont=<fontname>
%%     This option sets a font in which are typed the names of the rooms
%%     in which is that practice taught.
%%     Default value for absent environment option is `cmti10'.
%%
%%   linewidth=<DIMENSION>
%%     This influences width of all lines in the table.
%%     Default value is `0.4pt'.
%%
%%   linespacewidth=<DIMENSION>
%%     You can change the width of the space between the vertical lines
%%     on the left and on the right of the table by this option.
%%     Default value is `1.3pt'.
%%
%%   linespaceheight=<DIMENSION>
%%     You can change the height of the space between the vertical lines
%%     on the top and at the bottom of the table by this option.
%%     Default value is `1.2pt'.
%%
%%   MO=<text>
%%   TU=<text>
%%   WE=<text>
%%   TH=<text>
%%   FR=<text>
%%     This texts are typed in the first column of the table.
%%     Default values for absent environment option are `Monday', etc.
%%
%%   from=<text>
%%   to=<text>
%%     This texts are typed in the first column of the table. The beginning
%%     time and the end time of the each teaching hour are typed in the
%%     next columns.
%%     Default values for absent environment option are `from', `to'.
%%
%%   subjectsfrom=<timelist>
%%   subjectsto=<timelist>
%%     Timelist is a list of the beginning/end time of each teaching hour.
%%     The times are separated by pipes `|' and are in h:mm format.
%%
%% <DIMENSION>
%%   This are the standard TeX dimension types which consists from a number
%%   and from an unit like em, en, pt, dd, in, cm, sp, etc.
%%   It is good to use first two units which rely on the font size.
%%
%% BUGS
%%   It seem that there is a bug in dvips. If you would like create
%%   PostScript output, you can use pdfTeX and the print function of Xpdf.
%%
%%   If you find some bug in this TeX macro send me a report with your input
%%   please. However be sure of having the right input before sending a report.
%%   Criticism and admiration are welcome.
%%
%% EXAMPLE
%%   \timetable[tablewidth=15cm,heading=ZS 2001/2002,environment=czech,%
%%   subjectsfrom=7:30|8:15|9:15|10:00|11:00|11:45|||14:30||16:15,%
%%   subjectsto=|9:00|9:45|10:45|11:30|12:30||14:15||16:00|16:55|17:45|19:25]%
%%   {TU:P:11-2=TI-K3,TH:L:1-2=EL-209,MO:L:5-2=M5D-K1,FR:P:3-2=LS-K307,%
%%   TU:L:1-3=TI-K1,MO:OP:8-2=DBS-K5,TU:L:6-2=\TeX-340,TH:OP:5-2=SOJ-K310,%
%%   TH:L:9-3=LS-337,MO:L:2-3=DBS-K1,FR:P:1-2=NLP-T204,MO:EP:9-2=DBS-K311,%
%%   WE:EP:4-2=EL-041/9}
%%
%%
\edef\oldcountten{\the\count10\relax} % \count register
\edef\oldcounteleven{\the\count11\relax} % \dimen register
\edef\oldcountfourteen{\the\count14\relax} % \box register
\edef\oldcountfiveteen{\the\count15\relax} % \toks register
\newtoks\halignbody
\newcount\nrofdeclared
\newcount\nrofcolumns
\newcount\tempnum
\newcount\nextsubjectbeg
\newcount\restcolumns
\newcount\currentcolumn
\newcount\hruleoldbelowbeg
\newcount\hruleoldbelowdur
\newcount\hruleabovebeg
\newcount\hruleabovedur
\newcount\hrulemiddlebeg
\newcount\hrulemiddledur
\newcount\hrulebelowbeg
\newcount\hrulebelowdur
\newdimen\tempdimen
\newdimen\columnwidth
\newbox\tempbox
\def\timetable{\bgroup
 \def\myrelaxtocolon##1:{\relax}
 \def\declareto##1:{\let\next=\declareloop \next##1:}
 \def\declareloop##1:{
  \ifnum \nrofdeclared=##1 \let\next=\myrelaxtocolon
  \else \advance\nrofdeclared by 1
   \expandafter\def\csname col\the\nrofdeclared\endcsname{}
  \fi \next##1:}
 \def\analysethebeginning##1:##2:##3-##4=##5,{
  \ifnum##3>\nrofdeclared \declareto ##3: \fi
  \tempnum=##3
  \advance\tempnum by ##4
  \advance\tempnum by -1
  \ifnum \tempnum>\nrofcolumns \nrofcolumns=\tempnum \fi
  \ex\ex\ex\ex\ex\ex\ex\def\ex\ex\ex\ex\ex\ex\csname col##3\endcsname
   \ex\ex\ex{\csname col##3\endcsname ##1:##2:##3-##4=##5,}}
 \def\myrelaxtwo##1##2{\relax}
 \def\myrelaxone##1{\relax}
 \def\browse##1,{\browseaction##1,
  \futurelet \nextchar\testnextchar}
 \def\testnextchar{
  \ifx ,\nextchar \let\browsenext=\myrelaxtwo
  \else
   \ifx *\nextchar \let\browsenext=\myrelaxone \fi
  \fi
  \browsenext}
 \def\browsetimes##1|{\browseaction##1|
  \futurelet \nextchar\testnexttimeschar}
 \def\testnexttimeschar{
  \ifx *\nextchar \let\browsenext=\myrelaxone \fi
  \browsenext}
 \def\mergethebeginning{
  \def\subjects{}
  \def\add####1:{\ex\ex\ex\ex\ex\ex\ex \def \ex\ex\ex\ex\ex\ex\ex \subjects
   \ex\ex\ex\ex\ex\ex\ex{\ex\ex\ex \subjects \csname col####1\endcsname}}
  \tempnum=0 \let\next=\mergethenextbeginning \next}
 \def\mergethenextbeginning{
  \ifnum\tempnum=\nrofdeclared \let\next=\relax
  \else \advance\tempnum by 1 \expandafter\add\the\tempnum:
  \fi \next}
 \def\getfromhruleoldbelow##1-##2,##3*{
   \def\hruleoldbelow{##3}
   \hruleoldbelowbeg=##1
   \hruleoldbelowdur=##2\relax}
 \def\analyseOE##1:##2##3:##4-##5=##6,{
  \def\addoldbelowtohruleabove{
   \edef\hruleabove{\hruleabove \the\hruleoldbelowbeg-\the\hruleoldbelowdur,}}
  \def\addtohruleabove{
   \edef\hruleabove{\hruleabove \the\hruleabovebeg-\the\hruleabovedur,}
   \hruleabovebeg=##4
   \hruleabovedur=##5}
  \def\addtohrulemiddle{
   \edef\hrulemiddle{\hrulemiddle \the\hrulemiddlebeg-\the\hrulemiddledur,}
   \hrulemiddlebeg=##4
   \hrulemiddledur=##5}
  \def\addtohrulebelow{
   \edef\hrulebelow{\hrulebelow \the\hrulebelowbeg-\the\hrulebelowdur,}
   \hrulebelowbeg=##4
   \hrulebelowdur=##5}
  \def\hruleabovetest{
   \ifnum\hruleoldbelowbeg=0
    \ifx \empty\hruleoldbelow \let\next=\hruleabovetestwithoutoldbelow
    \else
     \let\next=\hruleaboveloop
     \let\getnextoldbelow=\getfromhruleoldbelowexp
    \fi
   \else
    \let\next=\hruleaboveloop
    \let\getnextoldbelow=\relax
   \fi \next}
  \def\getfromhruleoldbelowexp{
   \expandafter\getfromhruleoldbelow\hruleoldbelow *}
  \def\hruleabovetestwithoutoldbelow{
   \ifnum\hruleabovebeg>0
    \tempnum=\hruleabovebeg
    \advance\tempnum by \hruleabovedur
    \ifnum \tempnum<##4 % space
     \addtohruleabove
    \else 
     \tempnum=##4
     \advance\tempnum by ##5
     \advance\tempnum by -\hruleabovebeg
     \advance\tempnum by -\hruleabovedur
     \ifnum \tempnum>0
      \advance\hruleabovedur by \tempnum
     \fi
    \fi
   \else
    \hruleabovebeg=##4
    \hruleabovedur=##5
   \fi}
  \def\hruleaboveloop{
   \ifnum\hruleabovebeg>0 % not first pass?
    \ifnum\hruleoldbelowbeg=0
     \ifx \empty\hruleoldbelow \let\next=\relax
     \fi
    \fi
    \ifx \next\relax
    \else
     \getnextoldbelow
     \tempnum=##4
     \advance\tempnum by ##5
     \advance\tempnum by 1
     \ifnum \hruleoldbelowbeg<\tempnum 
      \ifnum \hruleoldbelowbeg<\hruleabovebeg
       \tempnum=\hruleoldbelowbeg
       \advance\tempnum by \hruleoldbelowdur
       \advance\tempnum by 1
       \ifnum \hruleabovebeg<\tempnum % 1
        \advance\hruleabovedur by \hruleabovebeg
        \advance\hruleabovedur by -\hruleoldbelowbeg
        \hruleabovebeg=\hruleoldbelowbeg
        \ifnum \hruleoldbelowdur>\hruleabovedur
         \hruleabovedur=\hruleoldbelowdur
        \fi
        \let\getnextoldbelow=\getfromhruleoldbelowexp
        \hruleoldbelowbeg=0
        \hruleoldbelowdur=0
       \else % 3
        \addoldbelowtohruleabove
        \let\getnextoldbelow=\getfromhruleoldbelowexp
        \hruleoldbelowbeg=0
        \hruleoldbelowdur=0
       \fi
      \else
       \tempnum=\hruleabovebeg
       \advance\tempnum by \hruleabovedur
       \advance\tempnum by 1
       \ifnum \hruleoldbelowbeg<\tempnum % 2
         \tempnum=\hruleoldbelowbeg
         \advance\tempnum by \hruleoldbelowdur
         \advance\tempnum by -\hruleabovebeg
         \advance\tempnum by -\hruleabovedur
         \ifnum \tempnum>0
          \advance\hruleabovedur by \tempnum
         \fi
        \let\getnextoldbelow=\getfromhruleoldbelowexp
        \hruleoldbelowbeg=0
        \hruleoldbelowdur=0
       \else % 4
        \tempnum=##4
        \advance\tempnum by ##5
        \advance\tempnum by -\hruleabovebeg
        \advance\tempnum by -\hruleabovedur
        \ifnum \tempnum>0 % Can the actual subject extend the hruleabove?
         \ifnum \tempnum>##5 % If the extension is longer than duration
          \addtohruleabove   % of the actual subject there must be a space.
         \else
          \advance\hruleabovedur by \tempnum
         \fi
        \fi
       \fi
      \fi
     \else % the next comparisons are in the authority of the next subject
      \tempnum=\hruleabovebeg
      \advance\tempnum by \hruleabovedur
      \advance\tempnum by 1
      \ifnum \tempnum>##4 %nospace
       \tempnum=##4
       \advance\tempnum by ##5
       \advance\tempnum by -\hruleabovebeg
       \advance\tempnum by -\hruleabovedur
       \ifnum \tempnum>0
        \advance\hruleabovedur by \tempnum
       \fi
      \else
       \addtohruleabove
      \fi
      \let\getnextoldbelow=\relax
      \let\next=\relax
     \fi
    \fi
   \else
    \hruleabovebeg=##4
    \hruleabovedur=##5
   \fi \next}
  \def\hrulemiddletest{
   \ifnum\hrulemiddlebeg>0
    \tempnum=\hrulemiddlebeg
    \advance\tempnum by \hrulemiddledur
    \ifnum ##4>\tempnum % space
     \addtohrulemiddle
    \else
     \advance\tempnum by -##4
     \multiply\tempnum by -1
     \advance\tempnum by ##5
     \ifnum\tempnum>0
      \advance\hrulemiddledur by \tempnum
     \fi
    \fi
   \else
    \hrulemiddlebeg=##4
    \hrulemiddledur=##5
   \fi}
  \def\hrulebelowtest{
   \ifnum\hrulebelowbeg>0
    \tempnum=\hrulebelowbeg
    \advance\tempnum by \hrulebelowdur
    \ifnum \tempnum=##4 % no space
     \advance\hrulebelowdur by ##5
    \else \addtohrulebelow
    \fi
   \else
    \hrulebelowbeg=##4
    \hrulebelowdur=##5
   \fi}
  \ifx :##3: % Is that non-alternating subject?
   \ex\def\ex\mylineO\ex{\mylineO ##1:O##2:##4-##5=-,}
   \ex\def\ex\mylineE\ex{\mylineE ##1:E##2:##4-##5=-,}
   \ifnum \hrulemiddledur>0
    \addtohrulemiddle
    \hrulemiddlebeg=0
    \hrulemiddledur=0
   \fi
   \let\testthehruleabove=\hruleabovetest
   \let\testthehrulemiddle=\relax
   \let\testthehrulebelow=\hrulebelowtest
   \ex\def\ex\myline\ex{\myline ##1:##2##3:##4-##5=##6,}
  \else
   \ifx O##2
    \let\testthehruleabove=\hruleabovetest
    \let\testthehrulemiddle=\hrulemiddletest
    \let\testthehrulebelow=\relax
    \ex\def\ex\mylineO\ex{\mylineO ##1:##2##3:##4-##5=##6,}
   \else
    \ifx E##2
     \let\testthehruleabove=\relax
     \let\testthehrulemiddle=\hrulemiddletest
     \let\testthehrulebelow=\hrulebelowtest
     \ex\def\ex\mylineE\ex{\mylineE ##1:##2##3:##4-##5=##6,}
    \else \errmessage{Bad input: ##1:##2##3:##4-##5=##6}
    \fi
   \fi
  \fi
  \testthehruleabove
  \testthehrulemiddle
  \testthehrulebelow}
 \def\analysetheday##1:##2,{
  \def\myday{##1}
  \ifx \dayMO\myday \ex\def\ex\mylineMO\ex{\mylineMO ##1:##2,}
  \else
   \ifx \dayTU\myday \ex\def\ex\mylineTU\ex{\mylineTU ##1:##2,}
   \else
    \ifx \dayWE\myday \ex\def\ex\mylineWE\ex{\mylineWE ##1:##2,}
    \else
     \ifx \dayTH\myday \ex\def\ex\mylineTH\ex{\mylineTH ##1:##2,}
     \else
      \ifx \dayFR\myday \ex\def\ex\mylineFR\ex{\mylineFR ##1:##2,}
      \else \errmessage{##1 is not valid format of the day of week.
       Use one of these - MO,TU,WE,TH,FR}
      \fi
     \fi
    \fi
   \fi
  \fi}
 \def\radixsort{
  \let\browseaction=\analysethebeginning
  \nrofdeclared=0
  \let\browsenext=\browse
  \expandafter\browse\subjects,*
  \mergethebeginning
  \tempnum=\nrofdeclared
  \nrofdeclared=0
  \expandafter\declareto\the\tempnum:
  \def\mylineMO{}
  \def\mylineTU{}
  \def\mylineWE{}
  \def\mylineTH{}
  \def\mylineFR{}
  \let\browseaction=\analysetheday
  \let\browsenext=\browse
  \expandafter\browse\subjects *
  \def\subjects{}}
 \def\testthetimetable{
  \ifx [\nextchar \let\next=\timetablewhopt
  \else \let\next=\timetablewhoutopt
  \fi \next}
 \def\timetablewhoutopt##1{\def\subjects{##1}
  \drawthetimetable}
 \def\timetablewhopt[##1]##2{\def\subjects{##2}
  \def\tablewidthopt{tablewidth}
  \def\headingopt{heading}
  \def\strutopt{strut}
  \def\forcehrulesopt{forcehrules}
  \def\forcevrulesopt{forcevrules}
  \def\environmentopt{environment}
  \def\headingfontopt{headingfont}
  \def\columnheadingfontopt{columnheadingfont}
  \def\rowheadingfontopt{rowheadingfont}
  \def\Lsubjectnamefontopt{Lsubjectnamefont}
  \def\Llocationfontopt{Llocationfont}
  \def\Psubjectnamefontopt{Psubjectnamefont}
  \def\Plocationfontopt{Plocationfont}
  \def\linewidthopt{linewidth}
  \def\linespacewidthopt{linespacewidth}
  \def\linespaceheightopt{linespaceheight}
  \def\fromopt{from}
  \def\toopt{to}
  \def\subjectsfromopt{subjectsfrom}
  \def\subjectstoopt{subjectsto}
  \let\browseaction=\analyseoptions
  \let\browsenext=\browse
  \browse##1,*
  \drawthetimetable}
 \def\analyseoptions##1,{
  \def\myoption{##1}
  \ifx \myoption\forcehrulesopt \let\drawthehrulesabove=\drawthelonghrule
  \else
   \ifx \myoption\forcevrulesopt \let\sepvrule=\relax
   \else \analyseequals##1,
   \fi
  \fi}
 \def\analyseequals##1=##2,{
  \def\myoption{##1}
  \ifx \myoption\tablewidthopt \def\tablewidth{to ##2}
  \else
   \ifx \myoption\headingopt \def\heading{##2}
   \else
    \ifx \myoption\environmentopt \def\environment{##2}
    \else
     \ifx \myoption\headingfontopt \font\headingfont=##2
     \else
      \ifx \myoption\columnheadingfontopt \font\columnheadingfont=##2
      \else
       \ifx \myoption\rowheadingfontopt \font\rowheadingfont=##2
       \else
        \ifx \myoption\Lsubjectnamefontopt \font\Lsubjectnamefont=##2
        \else
         \ifx \myoption\Llocationfontopt \font\Llocationfont=##2
         \else
          \ifx \myoption\Psubjectnamefontopt \font\Psubjectnamefont=##2
          \else
           \ifx \myoption\Plocationfontopt \font\Plocationfont=##2
           \else
            \ifx \myoption\linewidthopt
             \def\myhrule{\hrule height##2}
             \def\myvrule{\vrule width##2}
             \def\hrulefill{\leaders\myhrule\hfill}
            \else
             \ifx \myoption\linespacewidthopt
              \def\linespacewidth{\kern ##2}
             \else
              \ifx \myoption\linespaceheightopt
               \def\linespaceheight{\myvrule height##2}
              \else
               \ifx \myoption\dayMO \def\MO{##2}
               \else
                \ifx \myoption\dayTU \def\TU{##2}
                \else
                 \ifx \myoption\dayWE \def\WE{##2}
                 \else
                  \ifx \myoption\dayTH \def\TH{##2}
                  \else
                   \ifx \myoption\dayFR \def\FR{##2}
                   \else
                    \ifx \myoption\fromopt \def\from{##2}
                    \else
                     \ifx \myoption\toopt \def\to{##2}
                     \else
                      \ifx \myoption\subjectsfromopt
                       \def\subjectsfrom{##2}
                       \let\testthefromrow=\addthefromrow
                      \else
                       \ifx \myoption\subjectstoopt
                        \def\subjectsto{##2}
                        \let\testthetorow=\addthetorow
                       \else
                        \ifx \myoption\strutopt
                         \def\mystrut{\vrule width0pt ##2}
                        \else
                         \ifx \myoption\headingopt \def\heading{##2}
                         \else \errmessage{Bad option: ##1} 
                         \fi
                        \fi
                       \fi
                      \fi
                     \fi
                    \fi
                   \fi
                  \fi
                 \fi
                \fi
               \fi
              \fi
             \fi
            \fi
           \fi
          \fi
         \fi
        \fi
       \fi
      \fi
     \fi
    \fi
   \fi
  \fi}
 \def\emptythehrules{
  \def\myline{}
  \def\mylineO{}
  \def\mylineE{}
  \hruleoldbelowbeg=0
  \hruleoldbelowdur=0
  \hruleabovebeg=0
  \hruleabovedur=0
  \hrulemiddlebeg=0
  \hrulemiddledur=0
  \hrulebelowbeg=0
  \hrulebelowdur=0
  \def\hruleabove{}
  \def\hrulemiddle{}
  \def\hrulebelow{}}
 \def\testtherests{
  \ifnum\hruleabovebeg>0
   \addtohruleabove
  \else
   \ifx \empty\hruleabove
    \edef\hruleabove{\hruleoldbelow}
   \fi
  \fi
  \ifnum\hrulemiddlebeg>0 \addtohrulemiddle \fi
  \ifnum\hrulebelowbeg>0 \addtohrulebelow \fi
  \ifnum\hruleoldbelowbeg>0 \addoldbelowtohruleabove \fi}
 \def\divideintorows{
  \def\hruleoldbelow{}
  \emptythehrules
  \ifx \empty\mylineMO
  \else
   \let\browseaction=\analyseOE
   \let\browsenext=\browse
   \expandafter\browse\mylineMO *
   \testtherests
  \fi
  \ex\def\ex\mylineMOO\ex{\mylineO}
  \ex\def\ex\mylineMO\ex{\myline}
  \ex\def\ex\mylineMOE\ex{\mylineE}
  \edef\hrulemiddleMO{\hrulemiddle}
% TUESDAY
  \edef\hruleoldbelow{\hrulebelow}
  \emptythehrules
  \ifx \empty\mylineTU
   \edef\hruleaboveTU{\hruleoldbelow}
  \else
   \let\browseaction=\analyseOE
   \let\browsenext=\browse
   \expandafter\browse\mylineTU *
   \testtherests
   \edef\hruleaboveTU{\hruleabove}
  \fi
  \ex\def\ex\mylineTUO\ex{\mylineO}
  \ex\def\ex\mylineTU\ex{\myline}
  \ex\def\ex\mylineTUE\ex{\mylineE}
  \edef\hrulemiddleTU{\hrulemiddle}
% WEDNESDAY
  \edef\hruleoldbelow{\hrulebelow}
  \emptythehrules
  \ifx \empty\mylineWE
   \edef\hruleaboveWE{\hruleoldbelow}
  \else
   \let\browseaction=\analyseOE
   \let\browsenext=\browse
   \expandafter\browse\mylineWE *
   \testtherests
   \edef\hruleaboveWE{\hruleabove}
  \fi
  \ex\def\ex\mylineWEO\ex{\mylineO}
  \ex\def\ex\mylineWE\ex{\myline}
  \ex\def\ex\mylineWEE\ex{\mylineE}
  \edef\hrulemiddleWE{\hrulemiddle}
% THURSDAY
  \edef\hruleoldbelow{\hrulebelow}
  \emptythehrules
  \ifx \empty\mylineTH
   \edef\hruleaboveTH{\hruleoldbelow}
  \else
   \let\browseaction=\analyseOE
   \let\browsenext=\browse
   \expandafter\browse\mylineTH *
   \testtherests
   \edef\hruleaboveTH{\hruleabove}
  \fi
  \ex\def\ex\mylineTHO\ex{\mylineO}
  \ex\def\ex\mylineTH\ex{\myline}
  \ex\def\ex\mylineTHE\ex{\mylineE}
  \edef\hrulemiddleTH{\hrulemiddle}
% FRIDAY
  \edef\hruleoldbelow{\hrulebelow}
  \emptythehrules
  \ifx \empty\mylineFR
   \edef\hruleaboveFR{\hruleoldbelow}
  \else
   \let\browseaction=\analyseOE
   \let\browsenext=\browse
   \expandafter\browse\mylineFR *
   \testtherests
   \edef\hruleaboveFR{\hruleabove}
  \fi
  \ex\def\ex\mylineFRO\ex{\mylineO}
  \ex\def\ex\mylineFR\ex{\myline}
  \ex\def\ex\mylineFRE\ex{\mylineE}
  \edef\hrulemiddleFR{\hrulemiddle}
  \emptythehrules}
 \def\emptysubjectloop{
  \ifnum \tempnum>0
   \ifnum \tempnum>1
    \halignbody=\expandafter{\the\halignbody &&\sepvrule}
   \else
    \halignbody=\expandafter{\the\halignbody &&}
    \ifnum\currentcolumn>\nrofcolumns
     \halignbody=\ex\ex\ex{\ex\the\ex\halignbody\addstrut\cr}
    \fi
   \fi
   \advance\tempnum by -1
  \else
   \let\next=\relax
  \fi \next}
 \def\getnexthrulemiddle##1-##2,##3*{
  \hrulemiddlebeg=##1
  \hrulemiddledur=##2
  \def\hrulemiddle{##3}}
 \def\hrulesubjectsloop{
  \ifnum \hrulemiddlebeg=0
   \ifx \empty\hrulemiddle
    \tempnum=\nextsubjectbeg
    \advance\tempnum by -\currentcolumn
    \advance\currentcolumn by \tempnum
    \let\addstrut=\space
    \let\next=\emptysubjectloop
    \let\nexthruleloop=\next
   \else
    \expandafter\getnexthrulemiddle\hrulemiddle *
   \fi
  \fi
  \ifnum \hrulemiddlebeg>0
   \ifnum \nextsubjectbeg<\hrulemiddlebeg % add spaces to next subject
    \tempnum=\nextsubjectbeg
    \advance\tempnum by -\currentcolumn
    \advance\currentcolumn by \tempnum
    \let\next=\emptysubjectloop
    \next
   \else % add spaces to middlehrulebeg
    \tempnum=\hrulemiddlebeg
    \advance \tempnum by -\currentcolumn
    \ifnum \tempnum>0
     \advance\currentcolumn by \tempnum
     \let\next=\emptysubjectloop
     \next
    \fi
    \ifnum \hrulemiddlebeg=1
     \def\begvvrulecorrection{\vvrule}
    \else
     \def\begvvrulecorrection{\relax}
    \fi
    \tempnum=\hrulemiddlebeg
    \advance\tempnum by \hrulemiddledur
    \advance\tempnum by -1
    \ifnum \tempnum=\nrofcolumns
     \def\endvvrulecorrection{\vvrule}
    \else
     \def\endvvrulecorrection{\relax} 
    \fi
    \edef\correctedline{\begvvrulecorrection\hrulefill\endvvrulecorrection}
    \tempnum=\hrulemiddledur
    \multiply\tempnum by 2
    \advance\tempnum by 1
    \advance\currentcolumn by \hrulemiddledur
    \halignbody=\ex\ex\ex\ex\ex\ex\ex{\ex\ex\ex\the\ex\ex\ex\halignbody
     \ex\ex\ex\multispan\ex\ex\ex{\ex\the\ex\tempnum\ex}\correctedline}
    \ifnum \currentcolumn>\nrofcolumns
     \halignbody=\expandafter{\the\halignbody \cr}
    \fi
   \fi
   \ifnum\currentcolumn<\nextsubjectbeg
    \tempnum=\hrulemiddlebeg
    \advance\tempnum by \hrulemiddledur
    \advance\tempnum by -1
    \ifnum \currentcolumn>\tempnum
     \hrulemiddlebeg=0
    \fi
   \else
    \let\nexthruleloop=\relax
   \fi
  \fi
  \nexthruleloop}
 \def\testthecolumnwidth ##1##2=##3-##4,{
  \ifx L##1
   \setbox\tempbox=\hbox{\Lsubjectnamefont\ ##3\Llocationfont ##4\ }
  \else
   \setbox\tempbox=\hbox{\Psubjectnamefont\ ##3\Plocationfont ##4\ }
  \fi
  \tempdimen=\wd\tempbox
  \divide \tempdimen by ##2
  \ifnum \tempdimen>\columnwidth
   \columnwidth=\tempdimen
  \fi}
 \def\drawthesubject##1:##2##3:##4-##5=##6-##7,{
  \ifnum \currentcolumn<##4 % Is it necessary to add spaces?
   \if :##3: % add spaces with middlehrules
    \nextsubjectbeg=##4
    \hrulemiddlebeg=0
    \let\nexthruleloop=\hrulesubjectsloop
     \nexthruleloop
   \else % add spaces without hrules
    \edef\addstrut{\higheststrutfont\mystrut}
    \tempnum=##4
    \advance\tempnum by -\currentcolumn
    \advance\currentcolumn by \tempnum
    \let\next=\emptysubjectloop
    \next
   \fi
  \fi
  \tempnum=##5
  \multiply\tempnum by 2
  \advance\tempnum by -1
  \advance\currentcolumn by ##5
  \ifx :##3:
   \ifx L##2
    \halignbody=\ex\ex\ex{\ex\the\ex\halignbody \ex &\ex\multispan
     \ex{\the\tempnum}\hfil\hidewidth \vbox to0pt{\vss\hbox{\Lsubjectnamefont
      ##6 \mystrut\Llocationfont ##7\mystrut}\vss}\hidewidth\hfil &}
    \testthecolumnwidth L##5=##6-##7,
   \else
    \halignbody=\ex\ex\ex{\ex\the\ex\halignbody \ex &\ex\multispan
     \ex{\the\tempnum}\hfil\hidewidth \vbox to0pt{\vss\hbox{\Psubjectnamefont
      ##6 \mystrut\Plocationfont ##7\mystrut}\vss}\hidewidth\hfil &}
    \testthecolumnwidth P##5=##6-##7,
   \fi
   \ifnum\currentcolumn>\nrofcolumns
    \halignbody=\ex\ex\ex{\ex\the\ex\halignbody \cr}
   \fi
  \else
   \ifx L##3
    \halignbody=\ex\ex\ex{\ex\the\ex\halignbody \ex &\ex\multispan
     \ex{\the\tempnum}\hfil\hidewidth\Lsubjectnamefont ##6
      \Llocationfont ##7\hidewidth\hfil &}
    \testthecolumnwidth L##5=##6-##7,
   \else
    \halignbody=\ex\ex\ex{\ex\the\ex\halignbody \ex &\ex\multispan
     \ex{\the\tempnum}\hfil\hidewidth\Psubjectnamefont ##6
      \Plocationfont ##7\hidewidth\hfil &}
    \testthecolumnwidth P##5=##6-##7,
   \fi
   \ifnum\currentcolumn>\nrofcolumns
    \halignbody=\ex\ex\ex{\ex\the\ex\halignbody\addstrut \cr}
   \fi
  \fi}
 \def\hrulesaboveinit{
  \halignbody=\expandafter{\the\halignbody \multispan3\vvrule\hrulefill &}
  \currentcolumn=1
  \nextsubjectbeg=\nrofcolumns
  \advance\nextsubjectbeg by 1
  \let\nexthruleloop=\hrulesubjectsloop
  \nexthruleloop}
 \def\longhrule{\multispan3\vvrule\hrulefill&\multispan\restcolumns
  \span\omit\vvrule\hrulefill\vvrule\cr}
 \def\drawthelonghrule{\halignbody=\ex{\the\halignbody \longhrule}}
 \def\testonetime##1|{
  \ifnum \tempnum<\nrofcolumns
   \ifx |##1|
    \halignbody=\ex{\the\halignbody &&}
    \advance\tempnum by 1
   \else \typeonetime##1|
   \fi
  \fi}
 \def\typeonetime##1:##2|{
  \ifnum \tempnum<\nrofcolumns
   \halignbody=\ex{\the\halignbody &$##1^{##2\mathstrut}\mathstrut$&}
   \advance\tempnum by 1
   \setbox\tempbox=\hbox{\ $##1^{##2}$\ }
   \tempdimen=\wd\tempbox
   \ifnum \tempdimen>\columnwidth
    \columnwidth=\tempdimen
   \fi
  \fi}
 \def\addthefromrow{
  \def\lastvkern{\longhrule\vkern}
  \halignbody=\ex{\the\halignbody \longhrule &\rowheadingfont\from\mystrut &&}
  \let\browsenext=\browsetimes
  \let\browseaction=\testonetime
  \tempnum=0
  \expandafter\browsetimes\subjectsfrom |*
  \ifnum \tempnum<\nrofcolumns
   \nextsubjectbeg=\tempnum % nextsubjectbeg has the temporary value here
   \tempnum=\nrofcolumns
   \advance\tempnum by -\nextsubjectbeg
   \let\next=\emptytimesloop
   \next
  \fi
  \halignbody=\ex{\the\halignbody \mystrut\cr}}
 \def\addthetorow{
  \def\lastvkern{\longhrule\vkern}
  \halignbody=\ex{\the\halignbody \longhrule &\rowheadingfont\to\mystrut &&}
  \let\browsenext=\browsetimes
  \let\browseaction=\testonetime
  \tempnum=0
  \expandafter\browsetimes\subjectsto |*
  \ifnum \tempnum<\nrofcolumns
   \nextsubjectbeg=\tempnum % nextsubjectbeg has the temporary value here
   \tempnum=\nrofcolumns
   \advance\tempnum by -\nextsubjectbeg
   \let\next=\emptytimesloop
   \next
  \fi
  \halignbody=\ex{\the\halignbody \mystrut\cr}}
 \def\emptytimesloop{
  \ifnum \tempnum>0
   \halignbody=\expandafter{\the\halignbody &&}
   \advance\tempnum by -1
  \else
   \let\next=\relax
  \fi \next}
 \def\drawthetimetable{
  \ifx \empty\environment
   \ifx \empty\headingfont \font\headingfont=cmb10 \fi
   \ifx \empty\columnheadingfont \font\columnheadingfont=cmb10 \fi
   \ifx \empty\rowheadingfont \font\rowheadingfont=cmb10 \fi
   \ifx \empty\Lsubjectnamefont \font\Lsubjectnamefont=cmss10 \fi
   \ifx \empty\Llocationfont \font\Llocationfont=cmssi10 \fi
   \ifx \empty\Psubjectnamefont \font\Psubjectnamefont=cmr10 \fi
   \ifx \empty\Plocationfont \font\Plocationfont=cmti10 \fi
   \ifx \empty\MO \def\MO{Monday} \fi
   \ifx \empty\TU \def\TU{Tuesday} \fi
   \ifx \empty\WE \def\WE{Wednesday} \fi
   \ifx \empty\TH \def\TH{Thursday} \fi
   \ifx \empty\FR \def\FR{Friday} \fi
   \ifx \empty\from \def\from{from} \fi
   \ifx \empty\to \def\to{to} \fi
  \else
   \def\environmentopt{czech}
   \ifx \environment\environmentopt
    \ifx \empty\headingfont \font\headingfont=csb10 \fi
    \ifx \empty\columnheadingfont \font\columnheadingfont=csb10 \fi
    \ifx \empty\rowheadingfont \font\rowheadingfont=csb10 \fi
    \ifx \empty\Lsubjectnamefont \font\Lsubjectnamefont=csss10 \fi
    \ifx \empty\Llocationfont \font\Llocationfont=csssi10 \fi
    \ifx \empty\Psubjectnamefont \font\Psubjectnamefont=csr10 \fi
    \ifx \empty\Plocationfont \font\Plocationfont=csti10 \fi
    \ifx \empty\MO \def\MO{Pondìlí} \fi
    \ifx \empty\TU \def\TU{Úterý} \fi
    \ifx \empty\WE \def\WE{Støeda} \fi
    \ifx \empty\TH \def\TH{Ètvrtek} \fi
    \ifx \empty\FR \def\FR{Pátek} \fi
    \ifx \empty\from \def\from{od} \fi
    \ifx \empty\to \def\to{do} \fi
   \else 
    \def\environmentopt{slovak}
    \ifx \environment\environmentopt
     \ifx \empty\headingfont \font\headingfont=csb10 \fi
     \ifx \empty\columnheadingfont \font\columnheadingfont=csb10 \fi
     \ifx \empty\rowheadingfont \font\rowheadingfont=csb10 \fi
     \ifx \empty\Lsubjectnamefont \font\Lsubjectnamefont=csss10 \fi
     \ifx \empty\Llocationfont \font\Llocationfont=csssi10 \fi
     \ifx \empty\Psubjectnamefont \font\Psubjectnamefont=csr10 \fi
     \ifx \empty\Plocationfont \font\Plocationfont=csti10 \fi
     \ifx \empty\MO \def\MO{Pondelok} \fi
     \ifx \empty\TU \def\TU{Utorok} \fi
     \ifx \empty\WE \def\WE{Streda} \fi
     \ifx \empty\TH \def\TH{©tvrtok} \fi
     \ifx \empty\FR \def\FR{Piatok} \fi
     \ifx \empty\from \def\from{od} \fi
     \ifx \empty\to \def\to{do} \fi
    \else \errmessage{Unknown environment parameter: \environment}
    \fi
   \fi
  \fi
  \radixsort
  \divideintorows
  \def\vvrule{\myvrule\linespacewidth \myvrule}
  \def\vkern{\multispan\restcolumns
   \span\omit\span\omit\span\omit\span\omit
   \linespaceheight \hfil \linespaceheight \cr}
  \def\addtohalignmask{
   \ifnum \tempnum=\nrofcolumns
    \halignbody=\expandafter{\the\halignbody
     \hbox to\columnwidth{\hfil########\hfil}&########\vvrule\tabskip=0pt}
    \let\next=\relax
   \else
    \halignbody=\expandafter{\the\halignbody
     \hbox to\columnwidth{\hfil########\hfil}&########\myvrule&}
    \advance\tempnum by 1
   \fi \next}
  \restcolumns=\nrofcolumns
  \multiply\restcolumns by 2
  \halignbody={\tabskip=0pt plus 1fil\vvrule ####&
   \hfil\ ####\ \hfil & ####\tabskip=0pt &
   \tabskip=0pt plus 1fil\vvrule ####&}
  \tempnum=1
  \let\next=\addtohalignmask
  \next
  \halignbody=\expandafter{\the\halignbody \cr \noalign{\myhrule} \vkern \cr
   \longhrule &\headingfont\heading\mystrut&}
  \def\typetheheading{
   \ifnum \tempnum=\nrofcolumns
    \halignbody=\expandafter{\the\halignbody &\columnheadingfont\mystrut
     \cr \longhrule\vkern \cr \longhrule}
    \let\next=\relax
   \else
    \advance\tempnum by 1
    \ex\setbox\ex\tempbox\ex\hbox\ex{\ex\columnheadingfont\ex\ \the\tempnum\ }
    \tempdimen=\wd\tempbox
    \ifnum \tempdimen>\columnwidth
     \columnwidth=\tempdimen
    \fi
    \halignbody=\ex\ex\ex{\ex\the\ex\halignbody\ex&\ex&\ex\columnheadingfont
     \the\tempnum}
   \fi \next}
  \tempnum=0
  \let\next=\typetheheading
  \next
  \def\initOE{% alternating subjects
   \hrulemiddlebeg=0
   \halignbody=\expandafter{\the\halignbody &\omit &&}
   \currentcolumn=1
   \let\browsenext=\browse
   \let\browseaction=\drawthesubject
   \if \empty\subjects
   \else
    \expandafter\browse\subjects *
   \fi
   \ifnum \currentcolumn>\nrofcolumns
    \let\next=\relax
   \else
    \tempnum=\nrofcolumns
    \advance\tempnum by -\currentcolumn
    \advance\tempnum by 1
    \advance\currentcolumn by \tempnum
    \edef\addstrut{\higheststrutfont\mystrut}
    \let\next=\emptysubjectloop
   \fi \next}
  \def\init{% non alternating subjects
   \hrulemiddlebeg=0
   \currentcolumn=1
   \let\browsenext=\browse
   \let\browseaction=\drawthesubject
   \ifx \empty\subjects
   \else
    \expandafter\browse\subjects *
   \fi
   \nextsubjectbeg=\nrofcolumns
   \advance\nextsubjectbeg by 1
   \let\addstrut=\space
   \let\nexthruleloop=\hrulesubjectsloop
   \nexthruleloop}
% compute highest strut in subjects
  \setbox\tempbox=\hbox{\Lsubjectnamefont\mystrut}
  \tempdimen=\ht\tempbox % \tempdimen = the highest strut
  \let\higheststrutfont=\Lsubjectnamefont
  \setbox\tempbox=\hbox{\Psubjectnamefont\mystrut}
  \ifnum \tempdimen<\ht\tempbox
   \tempdimen=\ht\tempbox
   \let\higheststrutfont=\Psubjectnamefont
  \fi
  \setbox\tempbox=\hbox{\Llocationfont\mystrut}
  \ifnum \tempdimen<\ht\tempbox
   \tempdimen=\ht\tempbox
   \let\higheststrutfont=\Llocationfont
  \fi
  \setbox\tempbox=\hbox{\Plocationfont\mystrut}
  \ifnum \tempdimen<\ht\tempbox
   \tempdimen=\ht\tempbox
   \let\higheststrutfont=\Plocationfont
  \fi
% Monday
  \let\subjects=\mylineMOO
  \initOE
  \let\subjects=\mylineMO
  \let\hrulemiddle=\hrulemiddleMO
  \halignbody=\expandafter{\the\halignbody &\vbox to0pt{\vss
   \hbox{\rowheadingfont \MO\mystrut}\vss}&&}
  \init
  \let\subjects=\mylineMOE
  \initOE
% Tuesday
  \let\hrulemiddle=\hruleaboveTU
  \drawthehrulesabove
  \let\subjects=\mylineTUO
  \initOE
  \let\subjects=\mylineTU
  \let\hrulemiddle=\hrulemiddleTU
  \halignbody=\expandafter{\the\halignbody &\vbox to0pt{\vss
   \hbox{\rowheadingfont \TU\mystrut}\vss}&&}
  \init
  \let\subjects=\mylineTUE
  \initOE
% Wednesday
  \let\hrulemiddle=\hruleaboveWE
  \drawthehrulesabove
  \let\subjects=\mylineWEO
  \initOE
  \let\subjects=\mylineWE
  \let\hrulemiddle=\hrulemiddleWE
  \halignbody=\expandafter{\the\halignbody &\vbox to0pt{\vss
   \hbox{\rowheadingfont \WE\mystrut}\vss}&&}
  \init
  \let\subjects=\mylineWEE
  \initOE
% Thursday
  \let\hrulemiddle=\hruleaboveTH
  \drawthehrulesabove
  \let\subjects=\mylineTHO
  \initOE
  \let\subjects=\mylineTH
  \let\hrulemiddle=\hrulemiddleTH
  \halignbody=\expandafter{\the\halignbody &\vbox to0pt{\vss
   \hbox{\rowheadingfont \TH\mystrut}\vss}&&}
  \init
  \let\subjects=\mylineTHE
  \initOE
% Friday
  \let\hrulemiddle=\hruleaboveFR
  \drawthehrulesabove
  \let\subjects=\mylineFRO
  \initOE
  \let\subjects=\mylineFR
  \let\hrulemiddle=\hrulemiddleFR
  \halignbody=\expandafter{\the\halignbody &\vbox to0pt{\vss
   \hbox{\rowheadingfont \FR\mystrut}\vss}&&}
  \init
  \let\subjects=\mylineFRE
  \initOE
  \halignbody=\ex{\the\halignbody \longhrule \vkern}
  \testthefromrow
  \testthetorow
  \halignbody=\ex{\the\halignbody \lastvkern \noalign{\myhrule}}
  \expandafter\ialign\tablewidth{\span\the\halignbody}
  \egroup
% cancel the changes made by the \newcount commands etc.
  \count10=\oldcountten
  \count11=\oldcounteleven
  \count14=\oldcountfourteen
  \count15=\oldcountfiveteen}
% the beginning
 \offinterlineskip
 \nrofcolumns=0
 \def\tablewidth{}
 \def\heading{}
 \def\mystrut{\myvrule width0pt height1em depth.35em}
 \let\sepvrule=\omit
 \let\drawthehrulesabove=\hrulesaboveinit
 \let\testthefromrow=\relax
 \let\testthetorow=\relax
 \let\lastvkern=\space
 \def\environment{}
 \def\headingfont{}
 \def\columnheadingfont{}
 \def\rowheadingfont{}
 \def\Lsubjectnamefont{}
 \def\Llocationfont{}
 \def\Psubjectnamefont{}
 \def\Plocationfont{}
 \let\myhrule=\hrule
 \let\myvrule=\vrule
 \def\linespacewidth{\kern 1.3pt}
 \def\linespaceheight{\myvrule height1.2pt}
 \def\dayMO{MO}
 \def\dayTU{TU}
 \def\dayWE{WE}
 \def\dayTH{TH}
 \def\dayFR{FR}
 \def\MO{}
 \def\TU{}
 \def\WE{}
 \def\TH{}
 \def\FR{}
 \def\from{}
 \def\to{}
 \def\subjectsfrom{}
 \def\subjectsto{}
 \columnwidth=0pt
 \let\ex=\expandafter
 \futurelet\nextchar \testthetimetable}
\end