summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/plain/zztex/zzpage.tex
blob: a666c18094d4dc864daa21a0383198a94afc88d6 (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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Module:    ZzTeX Page Facilities
%
% Synopsis:  This module contains all the user facilities for
%            specifying things about the page layout.  It also
%            contains the output routines.
%
% Author:    Paul C. Anagnostopoulos
% Created:   7 March 1990
%
% Copyright 1989--2020 by Paul C. Anagnostopoulos
% under The MIT License (opensource.org/licenses/MIT)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%                       Tracing Page Makeup
%                       ------- ---- ------


\def \tracepagemakeup #1{%
  \if \posp{\tracingpagemakeup}%
    \writelog{ZzTeX page \the\pagenumber: #1}%
  \fi}

%                       Initialize Page Parameters
%                       ---------- ---- ----------


% Here we assume that the type area width is the same on both pages.

\def \zpageinit {%
  \gcalculate \trimplusbleedheight = {\standardbleed,+,\trimheight,+,%
                                      \standardbleed}%
  \gcalculate \trimplusbleedwidth = {\standardbleed,+,\trimwidth,+,%
                                     \standardbleed}%
  \gcalculate \typeareawidth = {\oddlefttextmargin,+,\textmeasure,+,%
                                \oddrighttextmargin}%
  \gcalculate \evenoutermargin = {\trimwidth,-,\typeareawidth,-,%
                                  \eveninnermargin}%
  \gcalculate \evenbleedshift = {-\evenlefttextmargin,-,\evenoutermargin,-,%
                                 \standardbleed}%
  \gcalculate \oddoutermargin = {\trimwidth,-,\typeareawidth,-,%
                                 \oddinnermargin}%
  \gcalculate \oddbleedshift = {-\oddlefttextmargin,-,\oddinnermargin,-,%
                                 \standardbleed}}

%                       Page Number
%                       ---- ------


\countdef \pagenumber = 0

\declaresnapitem{\pagenumber}

\def \setpagenumber #1{%                                {number}
  \global\pagenumber = #1\relax
  \setcolumnnumber{1}}

\def \evenpagep {\evenp{\pagenumber}}
\def \oddpagep {\oddp{\pagenumber}}

\def \folio {}

\def \setfoliostyle #1{%                                {\style}
  \ztoksa = \expandaftertwice{\name{#1folio}}%
  \xdef \folio {\the\ztoksa}}

\def \chapterpagefolio {\the\chaptercomptext-\number\pagenumber}
\def \arabicfolio {\number\pagenumber}
\let \decimalfolio = \arabicfolio
\def \letterfolio {\ucletter\pagenumber}
\def \partpagefolio {\the\partcomptext-\number\pagenumber}
\def \romanfolio {\romannumeral\pagenumber}

%                       Marks
%                       -----


% These macros hold the five parts of the current mark, each part having
% three subparts.  When a part is saved, the first subpart is expanded and
% the second and third subparts are not.

\definetoks{\zmarki}   \zmarki = {{???}{???}{???}}
\definetoks{\zmarkii}  \zmarkii = {{???}{???}{???}}
\definetoks{\zmarkiii} \zmarkiii = {{???}{???}{???}}
\definetoks{\zmarkiv}  \zmarkiv = {{???}{???}{???}}
\definetoks{\zmarkv}   \zmarkv = {{???}{???}{???}}


\def \setmarkinfothree #1#2#3#4{%       {part}{text1}{text2}{text3}
  {\tcounta = #1\relax
   \edef \znext {{#2}}%
   \global\name{\zmark\romannumeral\tcounta} = \expandafter{\znext{#3}{#4}}%
   \mark{\noexpand\or \the\zmarki \noexpand\or \the\zmarkii
         \noexpand\or \the\zmarkiii \noexpand\or \the\zmarkiv
         \noexpand\or \the\zmarkv}}%
  \if \vmodep \repeatpenalty \fi} % In case glue follows the mark.

\def \setmarkinfo #1#2#3{%                      {part}{text1}{text2}
  \setmarkinfothree{#1}{#2}{#3}{???}}


\let \firstnewmark = \firstmark
\let \bottommark = \botmark

\def \markinfo #1#2#3{%                         {mark}{part}{subpart}
  \ifcase #3%
    \relax
  \or
    \expandafter\zoneofthree
      \ifcase #2\expandafter\relax #1\else {???}{???}{???}\fi
  \or
    \expandafter\ztwoofthree
      \ifcase #2\expandafter\relax #1\else {???}{???}{???}\fi
  \or
    \expandafter\zthreeofthree
      \ifcase #2\expandafter\relax #1\else {???}{???}{???}\fi
  \else
    \error{invsubpart}{The subpart `#3' is invalid}%
  \fi}

%                       Page Screen
%                       ---- ------


\def \fullpagescreen #1{%                               {color}
  \if \inbackground
    \vskip -\standardbleed
    \moveleft \standardbleed \vbox{%
      \colorrule{#1}{width \trimplusbleedwidth height \trimplusbleedheight}}%
  \else
    \hrule width 0pt
    \vsinkfromtrim{-\standardbleed}
    \smashbox{%
      \colorparrule{#1}
        {\if \evenp{\pagenumber}\evenbleedshift \else \oddbleedshift \fi}
        {width \trimplusbleedwidth height 0pt depth \trimplusbleedheight}}%
  \fi}

%                       New Headers & Footers Scheme
%                       --- ------- - ------- ------


% Most of the definitions are in zzrunner.tex, but these need to be in
% here so they can be used in design files.


\def \headerblindformat {}

\def \footerblindformat {}

\def \headercornermarkformat {%
  \line{\vrule height .5pt depth 0pt width 6pt \hfil
        \vrule height .5pt depth 0pt width 6pt}%
  \nointerlineskip
  \line{\vrule height 6pt depth 0pt width .5pt \hfil
        \vrule height 6pt depth 0pt width .5pt}%
  \vfil}

\def \footercornermarkformat {%
  \vfil
  \line{\vrule height 6pt depth 0pt width .5pt \hfil
        \vrule height 6pt depth 0pt width .5pt}%
  \nointerlineskip
  \line{\vrule height .5pt width 6pt \hfil
        \vrule height .5pt width 6pt}}

%                       Old Headers & Footers Scheme
%                       --- ------- - ------- ------


\def \zcurheader{\normalheader}
\def \zcurfooter{\normalfooter}

\setflag \zoverrunners = \false
\let \zsaveheader = \relax
\let \zsavefooter = \relax


\def \setrunners #1#2{%                                 {header}{footer}
  \if \zoverrunners
    \gdef \zsaveheader {#1}%
    \gdef \zsavefooter {#2}%
  \else
    \gdef \zcurheader {#1}%
    \gdef \zcurfooter {#2}%
  \fi}

\def \overriderunners #1#2{%                            {header}{footer}
  \if \notp{\zoverrunners}%
    \global\let \zsaveheader = \zcurheader
    \global\let \zsavefooter = \zcurfooter
    \global\setflag \zoverrunners = \true
  \fi
  \gdef \zcurheader {#1}%
  \gdef \zcurfooter {#2}}

\def \blindrunners {%
  \overriderunners{\blindheader}{\blindfooter}}

\def \zsetrunnerstoks #1{%                              {tokens}
  \expandafter\overriderunners \the#1}

\def \zoverriderunnerstoks #1{%                              {tokens}
  \expandafter\overriderunners \the#1}

% The following macro is used to initialize the \runners parameter.

\def \zoldrunners #1{%
  \runners = {#1}}

% The following macro is called from the output routine.

\def \znextpagerunners {%
  \if \zoverrunners
    \global\let \zcurheader = \zsaveheader
    \global\let \zcurfooter = \zsavefooter
    \global\setflag \zoverrunners = \false
  \fi}


% The following macros provide some standard, simple header and footer
% formats.

\def \blindheader {}

\def \blindfooter {}

\def \cornermarkheader {\headercornermarkformat}

\def \cornermarkfooter {\footercornermarkformat}

% The following header and footer formats are provided by the design.
% Just in case they are forgotten:

\def \normalheader {%
  \warning{noheadfoot}{No normal header format has been specified}}
\def \normalfooter {%
  \warning{noheadfoot}{No normal footer format has been specified}}
\def \chapterheader {%
  \warning{noheadfoot}{No chapter header format has been specified}}
\def \chapterfooter {%
  \warning{noheadfoot}{No chapter footer format has been specified}}

%                       Multiple Columns
%                       -------- -------


% The following parameters are calculated by the \setpagecolumns command:

\setflag \zdofullbreak = \false         % True if doing a full break.
\setflag \zusetypewidth = \false        % True if using type area width.

\definecount{\columncount}{0}           % Number of columns on page.
\definecount{\columnnumber}{0}          % Current column number.
% \hsize
% \vsize


% The \setpagecolumns command accepts the following options:
%
%   \fullbreak
%   \shortbreak
%   \usetextmeasure
%   \usetextwidth
%   \usetypewidth

\def \setpagecolumns #1#2#3{%           {options}{columns}{gutter-width}
  \endgraf
  {\def \fullbreak {\global\setflag \zdofullbreak = \true}%
   \def \shortbreak {\global\setflag \zdofullbreak = \false}%
   \def \usetextmeasure {\global\setflag \zutw = \false}%
   \def \usetextwidth {\global\setflag \zutw = \false}%
   \def \usetypewidth {\global\setflag \zutw = \true}%
   \global\setflag \zdofullbreak = \false
   \global\setflag \zutw = \false
   #1}%
  \if \andp{\zusetypewidth}{\notp{\zutw}}%
    \zejectcolpage
  \else\if \onep{\columncount}%
    \if \orp{\gtrp{#2}{1}}{\zutw}\penalty \zpenoneton \fi
  \else\if \neqlp{#2}{\columncount}%
    \zejectcolpage
  \fi\fi\fi
  \global\columncount = #2\relax
  \global\setflag \zusetypewidth = \zutw
  \tdimena = \if \zusetypewidth \typeareawidth \else \textmeasure \fi
  \calculate \tdimenb = {-#3,*,\columncount,+,#3,+,\tdimena,/,\columncount}%
  \settextwidth{\tdimenb}%
  \global\hsize = \hsize                % Make these two parameters global.
  \global\parfillskip = \parfillskip
  \setcolumnnumber{1}%
  \tracepagemakeup{Columns: \the\columncount; width: \the\hsize; gutter: #3.}}

\def \zejectcolpage {%
  \if \zdofullbreak
    \freshpage{\full\floats\any}%
  \else
    \freshpage{\short\floats\any}%
  \fi
  \global\vsize = \textareaheight}      % Needed even if no page eject.


\def \setcolumnnumber #1{%                              {number}
  \global\columnnumber = #1\relax
  \if \andp{\oddpagep}{\lastcolumnp}%
    \global\brokenpenalty = \oddbrokenpenalty
  \else
    \global\brokenpenalty = \evenbrokenpenalty
  \fi}

\def \firstcolumnp {\eqlp{\columnnumber}{1}}
\def \lastcolumnp  {\eqlp{\columnnumber}{\columncount}}


%-----------------------------------------------------------------------------
%
% This old command is deprecated, although it will work forever.


\def \setcolumns #1#2#3{%               {count}{gutter-width}{use-type-area}
  \endgraf
  \if \andp{\zusetypewidth}{\notp{#3}}%
    \freshpage{\short\floats\any}%
    \global\vsize = \textareaheight % Needed even if no page eject.
  \else \if \eqlp{\columncount}{1}%
    \if \orp{\gtrp{#1}{1}}{#3}%
      \penalty \zpenoneton
    \fi
  \else \if \neqlp{#1}{\columncount}%
    \freshpage{\short\floats\any}%
    \global\vsize = \textareaheight % Needed even if no page eject.
  \fi\fi\fi
  \global\columncount = #1\relax
  \global\setflag \zusetypewidth = #3\relax
  {\zpageinit
   \tdimena = #2\relax
   \multiply \tdimena by \columncount
   \advance \tdimena by -#2\relax
   \if \zusetypewidth
     \advance \tdimena by -\typeareawidth
   \else
     \advance \tdimena by -\textmeasure
   \fi
   \divide \tdimena by -\columncount
   \settextwidth{\tdimena}%
   \global\hsize = \hsize               % Make these two parameters global.
   \global\parfillskip = \parfillskip}%
  \setcolumnnumber{1}%
  \tracepagemakeup{Columns: \the\columncount; width: \the\hsize; gutter: #2.}}

%                       Column Breaks
%                       ------ ------


\def \columnbreak #1{%                          {penalty}
  \penalty #1\relax}

\def \freshcolumn #1{%                          {options}
  {\let \zfill = \relax
   \let \full = \relax \def \short {\def \zfill {\vfill}}%
   #1\relax%
   \if \notp{\dimzerop{\lastskip}}\vskip -\lastskip \fi
   \zfill
   \penalty \zpenfreshcol}}

\def \fullcolumnbreak {\freshcolumn{\full}}
\def \shortcolumnbreak {\freshcolumn{\short}}

\def \blankcolumn {%
  \line{}%
  \shortcolumnbreak}

%                       Page Breaks
%                       ---- ------


%~ This command starts a new page. The options specify the
%~ exact behavior:
%~ & |\any|& Start an even or odd page.
%~ & |\even|&  Start an even page.
%~ & |\floats|& Place all floats before new page.
%~ & |\full|& Current page is bottomed out.
%~ & |\nofloats|& No need to place all floats.
%~ & |\odd|& Start an odd page.
%~ & |\short|& Run current page short.
%~ &.

\def \freshpage #1{%                            {options} %^page_makeup
  \if \vmodep
    {\let \zfill = \vfill
     \let \short = \relax \def \full {\let \zfill = \relax}%
     \let \zflush = \zpenfreshpage
     \let \nofloats = \relax \def \floats {\let \zflush = \zpenflushpage}%
     \let \zpage = \relax
     \let \any = \relax
     \def \odd {\def \zpage {\if \evenpagep \blankpage \fi}}%
     \def \even {\def \zpage {\if \oddpagep \blankpage \fi}}%
     #1\relax%
     \if \notp{\dimzerop{\lastskip}}\vskip -\lastskip \fi
     \zfill
     \if \notp{\lastcolumnp}%
       \penalty \zpenfreshcol
       \if \notp{\lastcolumnp}%
         \loop
           \blankcolumn
         \if \notp{\lastcolumnp}\repeat
       \fi
       \line{}%
       \vfill
     \fi
     \penalty \zflush
     \zpage}%
  \else
    \error{pagepar}{Page break requested in the middle of a paragraph}%
  \fi}

%~ This command starts a new page, bottoming out the current page.

\def \fullpagebreak {\freshpage{\full\nofloats\any}}    %^page_makeup

%~ This command starts a new page, leaving the current page short.
%~ The argument specifies the number of lines short, or, if 
%~ specified as |\asap|, runs the page as short as possible.

\def \shortpagebreak #1{%                               {lines} %^page_makeup
  {\def \zarg {#1}\def \zasap {\asap}%
   \if \tokeqlp{\zarg}{\zasap}%
     \freshpage{\short\nofloats\any}%
   \else
     \kern -\dp\strutbox
     \kern #1\baselineskip
     \fullpagebreak
   \fi}}

\def \blankpage {%
  \blindrunners
  \pagehint{(blank)}%
  \hrule width 0pt
  \freshpage{\short\nofloats\any}}

\def \blankleaf {%
  \freshpage{\short\floats\odd}
  \blankpage
  \freshpage{\short\even}
  \blankpage}

%                       Overriding Text Area Height
%                       ---------- ---- ---- ------


\definedimen{\zortahsave}{0pt}          % Saved normal text area height.
\definecount{\zortahcount}{0}           % Number of overridden pages.


%~ This command changes the number of lines on the specified number
%~ of pages, beginning with the current page. The nominal line count
%~ is increased or decreased by the specified number of lines,
%~ which should be coded with a plus or minus sign. A fractional
%~ number of lines is allowed. It is best to change two pages (a spread)
%~ with each command.

\def \overridetextareaheight #1#2{%             {pages}{lines} %^page_makeup
  \if \posp{\zortahcount}%
    \warning{overortah}{Text area height overridden during previous override}%
    \zresetortah
  \fi
  {\global\zortahsave = \textareaheight
   \global\zortahcount = #1\relax
   \global\advance \textareaheight by #2\baselineskip
   \global\vsize = \textareaheight
   \if \dimneqlp{\pagegoal}{\maxdimen}%
     \tdimena = \textareaheight
     \advance \tdimena by -\zortahsave
     \advance \tdimena by \pagegoal
     \global\pagegoal = \tdimena
   \fi}%
  \tracepagemakeup{Overriding text area height: pages: #1, vsize: \the\vsize, 
                   goal: \the\pagegoal.}}

\def \zresetortah {%
  \global\zortahcount = 0
  \global\textareaheight = \zortahsave
  \global\vsize = \textareaheight
%%%  \global\pagegoal = \vsize
  \tracepagemakeup{Un-overriding text area height: vsize: \the\vsize.}}

\def \zortahdivfinal {%
  \if \posp{\zortahcount}%
    \warning{divortah}{Text area height overridden across a division}%
    \zresetortah
  \fi}

%                       Text Margins
%                       ---- -------


% The following two macros are really bogus, because TeX doesn't
% always know what page it's on, except in the output routine.

\def \thislefttextmargin {%
  \if \evenpagep \evenlefttextmargin \else \oddlefttextmargin \fi}

\def \thisrighttextmargin {%
  \if \evenpagep \evenrighttextmargin \else \oddrighttextmargin \fi}

\definedimen{\typeareashift}{0pt}
\definecount{\ztaspage}{0}

\def \determinetypeareashift #1{%                               {page}
  \global\typeareashift = \if \evenp{#1}-\evenlefttextmargin \else
                                        -\oddlefttextmargin \fi}

%                       Layout Summary
%                       ------ -------


{\catcode`\_ = \catactive

\gdef \zlayoutsummary {%
  {\def _{\space}%
   \writelog{}%
   \writelog{Layout:}%
   \writelog{}%
   \tdimena = .013837\trimwidth
   \tdimenb = .013837\trimheight
   \writelog{Trim: \thefactor\tdimena"_x_\thefactor\tdimenb"}%
   \tdimena = .013837\headmargin
   \writelog{Head margin: \thefactor\tdimena"}%
   \tdimena = .083333\typeareawidth
   \tdimenb = .083333\typeareaheight
   \writelog{Type area: \thefactor\tdimena pc_x_\thefactor\tdimenb pc}%
   \tdimena = .013837\eveninnermargin
   \tdimenb = .013837\oddinnermargin
   \writelog{Inside margins: even \thefactor\tdimena", odd \thefactor\tdimenb"}%
   \tdimena = .013837\evenoutermargin
   \tdimenb = .013837\oddoutermargin
   \writelog{Outside margins: even \thefactor\tdimena", odd \thefactor\tdimenb"}%
   \tdimena = .083333\evenlefttextmargin
   \tdimenb = .083333\oddlefttextmargin
   \writelog{Left text margins: even \thefactor\tdimena pc,
                                odd \thefactor \tdimenb pc}%
   \tdimena = .083333\evenrighttextmargin
   \tdimenb = .083333\oddrighttextmargin
   \writelog{Right text margins: even \thefactor\tdimena pc,
                                 odd \thefactor\tdimenb pc}%
   \tdimena = .083333\textmeasure
   \tdimenb = .083333\textareaheight
   \writelog{Text area: \thefactor\tdimena pc_x_\thefactor\tdimenb pc}%
   \writelog{Top skip: \the\topskip, delta: \the\topdelta}%
   \writelog{}}}

}% \catcode

%                       Debugging
%                       ---------


\def \zlogoutf {-1}                     % First page to log.
\def \zlogoutl {-1}                     % Last page to log.


\def \logoutput #1#2{%                  {first-page}{last-page}
  \global\def \zlogoutf {#1}%
  \global\def \zlogoutl {#2}}

%                       Output Routine
%                       ------ -------


% The following definitions are for special penalties that control
% page makeup:

\def \zpennormal    {-10000\relax}      % Normal page break.
\def \zpenoneton    {-10001\relax}      % Switch from 1 to n columns.
\def \zpenfreshcol  {-10002\relax}      % Fresh column.
\def \zpenfreshpage {-10003\relax}      % Fresh page.
\def \zpenflushpage {-10004\relax}      % Fresh page, and flush floats.
\def \zpenfloatpage {-10005\relax}      % Page of floats scheduled.

% We need to put the depth of box 255 in a convenient place.

\definedimen{\zoutputcoldepth}{0pt}

% We must save \mathdisplayprevgraf across the output routine.

\definecount{\zsavemdpg}{0}

% The following boxes hold parts of the page:

\definebox{\zcolbox}            % One column's worth.
\definebox{\zbodybox}           % The body, multiple columns' worth.
\definebox{\zonetonbox}         % Stuff preceding 1- to n-column switch.
\setflag \zonetontype = \false  % True if 1-to-n text uses type area width.

% This toks register is invoked at the beginning of every column, so that
% things like index carryovers can be performed.

\definetoks{\everycolumn}
\everycolumn = {\relax}


\output = {\zoutput}

\def \zoutput {%
  \if \andp{\notp{\lssp{\pagenumber}{\zlogoutf}}}%
           {\notp{\gtrp{\pagenumber}{\zlogoutl}}}%
    \tracingoutput = 1
    \showboxdepth = 1000 \showboxbreadth = 1000\relax
  \fi
  \tracepagemakeup{[Output routine invoked for column \the\columnnumber;
                    penalty: \the\outputpenalty.}%
  \tracepagemakeup{Vsize: \the\vsize;
                   Box 255: \the\ht255+\the\dp255 \space x \the\wd255.}%
  \zoutputcoldepth = \dp255\relax
  \let \zsavewith = \zwith              % Save these items across the
  \let \zsavevariant = \zvariant        % output routine in case they
  \zsavemdpg = \mathdisplayprevgraf     % are altered within it.
  \normalbaselines
  \let \par = \endgraf
  \everyparagraph = {}%
  \spaceskip = 0pt
  \tcounta = \outputpenalty
  \if \eqlp{\tcounta}{-'10000000000}\tcounta = \zpenflushpage \fi
  \if \gtrp{\tcounta}{-10000}\tcounta = -10000\relax \fi
  \negate \tcounta
  \advance \tcounta by -10000\relax
  \ifcase \tcounta
    \zpagenormal \or
    \zpageoneton \or
    \zpagefreshcol \or
    \zpagefreshpage \or
    \zpageflushpage \or
    \zpagefloatpage \else
    \zzerror{Invalid page break penalty: \the\outputpenalty}%
  \fi
  \global\let \zvariant = \zsavevariant
  \global\let \zwith = \zsavewith
  \global\mathdisplayprevgraf = \zsavemdpg
  \tracepagemakeup{Output routine complete.]}}

\def \zpagenormal {%
  \tracepagemakeup{Process normal column.}%
  \zcolumnsave
  \if \lastcolumnp
    \zpagecontents
    \setcolumnnumber{1}%
  \else
    \tcounta = \columnnumber \increment \tcounta
    \setcolumnnumber{\tcounta}%
  \fi
  \zfloatinit
  \zschedulefloats{\zfloatcount}{\true}{\false}%
  \if \gtrp{\zfloatcount}{99}%
    \zfltpage{\zpenfloatpage}%
  \else
    \zeverycol
  \fi}

\def \zpageoneton {%
  \tracepagemakeup{Process 1- to n-column transition.}%
  \zonetoncolumnbody
  \global\setflag \zonetontype = \zusetypewidth
  \global\advance \vsize by -\ht\zonetonbox
  \global\advance \vsize by -\dp\zonetonbox
  \tracepagemakeup{Space remaining on page: \the\vsize.}}

\def \zpagefreshcol {%
  \tracepagemakeup{Process `fresh column' request.}%
  \zpagenormal}

\def \zpagefreshpage {%
  \tracepagemakeup{Process `fresh page' request.}%
  \zpagenormal}

\def \zpageflushpage {%
  \tracepagemakeup{Process `fresh page, flush floats' request.}%
  \zcolumnsave
  \if \lastcolumnp
    \zpagecontents
    \setcolumnnumber{1}%
  \else
    \tcounta = \columnnumber \increment \tcounta
    \setcolumnnumber{\tcounta}%
  \fi
  \zfloatinit
  \zschedulefloats{\zfloatcount}{\true}{\true}%
  \if \posp{\zfloatcount}%
    \zfltpage{\zpenflushpage}%
  \else
    \zeverycol
  \fi}

\def \zpagefloatpage {%
  \tracepagemakeup{Process page of floats.}%
  \zcolumnsave
  \if \lastcolumnp
    \zpagecontents
    \setcolumnnumber{1}%
  \else
    \tcounta = \columnnumber \increment \tcounta
    \setcolumnnumber{\tcounta}%
  \fi
  \zfloatinit
  \zschedulefloats{\zfloatcount}{\true}{\false}%
  \if \gtrp{\zfloatcount}{99}%
    \zfltpage{\zpenfloatpage}%
  \fi}

\def \zfltpage #1{%                                     {penalty}
  \if \notp{\emptytoksp{\zfltrunners}}%
    \zoverriderunnerstoks{\zfltrunners}%
  \fi
  {\leftskip = 0pt \rightskip = 0pt
   \line{}}%
  \kern -\topskip               % Why bother to do this?
  \nobreak \vfill
  \penalty #1}

\def \zeverycol {%
  {\zadjtitle = \zadjtitlemark          % \adjusttitle should adjust mark.
   \def \zadjloc {\mark}%
   \the\everycolumn}}

%                       Page Makeup: Column
%                       ---- ------- ------


\def \zcolumnsave {%
  \zcolumnbody
  \if \firstcolumnp
    \global\setbox \zbodybox = \hbox to \zbodyboxwidth {\box\zcolbox \hss}%
    \ztoksa = \expandafter{\topmark}%
    \xdef \topmarki {\the\ztoksa}%
    \ztoksa = \expandafter{\firstnewmark}%
    \xdef \firstnewmarki {\the\ztoksa}%
    \ztoksa = \expandafter{\bottommark}%
    \xdef \bottommarki {\the\ztoksa}%
  \else
    \global\setbox \zbodybox = \hbox to \zbodyboxwidth {%
      \unhbox\zbodybox \hfill \box\zcolbox}%
  \fi}

\def \zbodyboxwidth {%
  \if \zusetypewidth \typeareawidth \else \textmeasure \fi}

\def \zcolumnbody {%
  \tracepagemakeup{Wrapping up the column; hsize: \the\hsize.}%
  {\vbadness = 10000\relax
   \global\setbox \zcolbox = \vbox to \vsize {%
     \setindentation{0pt}{0pt}%
     \boxmaxdepth = \maxdepth
     \if \notp{\voidboxp{\ztopcolinsert}}\unvbox \ztopcolinsert \fi
     \unvbox 255 % Page built by TeX.
     \if \risingfootnotes
       \if \notp{\voidboxp{\zfninsert}}\zfootnoteformat{\zoutputcoldepth}\fi
     \fi
     \if \risingbottomfloats
       \if \notp{\voidboxp{\zbotcolinsert}}\unvbox \zbotcolinsert \fi
     \fi
     \if \raggedbottom
       \kern -\zoutputcoldepth \vfill
     \fi
     \if \notp{\risingfootnotes}%
       \if \notp{\voidboxp{\zfninsert}}\zfootnoteformat{\zoutputcoldepth}\fi
     \fi
     \if \notp{\risingbottomfloats}%
       \if \notp{\voidboxp{\zbotcolinsert}}\unvbox \zbotcolinsert \fi
     \fi}}}

% This is a special version of \zcolumnbody for the 1- to n-column
% transition.

\def \zonetoncolumnbody {%
  \global\setbox \zonetonbox = \vbox{%
    \setindentation{0pt}{0pt}%
    \boxmaxdepth = \maxdepth
    \if \notp{\voidboxp{\ztopcolinsert}}\unvbox \ztopcolinsert \fi
    \unvbox 255 % Page built by TeX.
    \vskip \baselineskip
    \vskip -\topskip
    % Ignore footnotes.
    % Ignore bottom style.
    % Ignore bottom floats.
    % Don't produce text area bottom rule.
    }}

%                       Page Makeup: Page
%                       ---- ------- ----


\def \zpagecontents {%
  \tracepagemakeup{Shipping out the final page.}%
  \shipout \vbox to \trimheight {%
    \parskip = 0pt \parindent = 0pt
    \setindentation{0pt}{0pt}%
    \zpageheadmargin
    \nointerlineskip
    \zpagetypearea
    \vfil
    \nointerlineskip
    \zpageoverlay}%
  \if \posp{\zortahcount}%             % If overriding text area height:
    \global\decrement \zortahcount
    \if \zerop{\zortahcount}\zresetortah \fi
  \fi
  \tcounta = \pagenumber \increment \tcounta
  \setpagenumber{\tcounta}%
  \global\vsize = \textareaheight % In case it was reset for this page.
  \znextpagerunners}

\def \zpagelengthmarks {%
  \tdimena = \headmargin
  \advance \tdimena by \typeareaheight
  \advance \tdimena by -\footerheight
  \vskip \tdimena
  \vbox to 0pt{%
    \hbox to \trimwidth{%
      \llap{\vrule height .5pt width .75pc}\hfil
      \rlap{\vrule height .5pt width .75pc}}%
    \vss}
  \vskip -\tdimena
  \nointerlineskip}

\setflag \inbackground = \false

\def \zpageheadmargin {%
  \vbox to \headmargin {%
    \hrule height 0pt width \trimwidth
    \nointerlineskip
    \smashbox{%
      \setflag \inbackground = \true
      \zcurback}%
    \nointerlineskip
    \vfil
    \zmakeuprule{\trimwidth}{.5pt}}}

\def \zpagetypearea {%
  \if \evenpagep
    \negate \eveninnermargin
    \advance \eveninnermargin by \trimwidth
    \advance \eveninnermargin by -\evenlefttextmargin
    \advance \eveninnermargin by -\textmeasure
    \advance \eveninnermargin by -\evenrighttextmargin
  \fi
  \moveright \if \oddpagep \oddinnermargin \else \eveninnermargin \fi
  \vbox to \typeareaheight {%
    \zadjtitle = \zadjtitlemark         % \adjusttitle should adjust mark.
    \def \zadjloc {\mark}%
    \zpageheader
    \nointerlineskip
    \ztextandmargins
    \zmakeuprule{\typeareawidth}{.5pt}%
    \vss                                % Allows text area height to vary.
    \vbox to \footerheight{%
      \vss
      \zpagefooter}}}

\def \zpageheader {%
  \vbox to \headerheight {%
    \hsize = \typeareawidth
    \zoutputbeginblack
    \zcurheader
    \zoutputendblack
    \vfil
    \zmakeuprule{\typeareawidth}{.5pt}}}

\def \ztextandmargins {%
  \hbox to \typeareawidth {%
    \if \notp{\zusetypewidth}%
      \hbox to \thislefttextmargin{\hss}%
    \fi
    \vbox{%
      \boxmaxdepth = \maxdepth
      \if \andp{\zusetypewidth}{\notp{\zonetontype}}%
        \moveright \thislefttextmargin
      \fi
      \box\zonetonbox
      \nointerlineskip
      \vbox{\box\zbodybox}}%
    \hss}}

\def \zpagefooter {%
  \hsize = \typeareawidth
  \zoutputbeginblack
  \zcurfooter
  \zoutputendblack
  \if \PDFhyperlinks \PDFmark{P:\folio}\fi}

% This macro invokes the page overlay after positioning to the
% upper-left corner of the trim.

\def \zpageoverlay {%
  \vbox to 0pt{%
    \offinterlineskip
    \kern -\trimheight
    \name{\pageoverlay\the\zoverlay}%
    \vss}}

\def \zmakeuprule #1#2{%                                {width}{height}
  \if \DVIWindoinuse
    \colorspecial{ifview color push rgb 0 1 0}%
    \tdimena = #1\tcounta = \tdimena
    \tdimena = #2\tcountb = \tdimena
    \special{viewrule: \the\tcounta\space \the\tcountb}%
    \colorspecial{ifview color pop}%
  \fi}