summaryrefslogtreecommitdiff
path: root/macros/psizzl/chapters.psizzl
blob: 1dc8efdb71afc0b15061fa8cabf3696af8a4201f (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
% CHAPTERS PSIZZL - generate the body of the publication
%
% CHAPTER MACRO
%
% \chapter{title}
%                            This command numbers the chapter,
%                            generates part of the number to be
%                            used in defining equation numbers,
%                            centers the line and prints it in
%                            boldface type.
%    When the above macro is to be used,
%    you first set up with the macro
%
% \beginbody
%
%    Then you define the chapters:
%
% \chapter{<chaptertitle>}%
%
%    where <chaptertitle> may contain embedded \breaktitle macros
%
%    After the \chapter for the last chapter, input the commnad:
%
% \beginappendices,
%
%    then more \chapter's for the appendices:
%
% \chapter{<appendixtitle>}%
%
%    Within each chapter, the current chapter name will be \chaptername
%    (for appendices, this will be a letter).
%
%    You may use macros to define sections and subsections within
%    chapters:
%
% \section{<section name>}%
%
% \subsection{<subsection name>}%
%
%    To output the tables of figures, etc. at the end, give the command:
%
% \endbody
%
%
\def\n@llout#1{\immediate\closeout#1\immediate\openout#1}%
\newcount\partcount
\def\p@rtinit{\partcount\@ne}%
\adddef\resd@c{\p@rtinit}%
\newcount\t@cpagecount\t@cpagecount\m@ne
\newcount\f@gpagecount\f@gpagecount\m@ne
\newcount\t@bpagecount\t@bpagecount\m@ne
\newcount\l@stpagecount\l@stpagecount\m@ne
\newif\ifpartapp
\newwrite\p@rtwrite
\def\p@rtfile{parts.psiztemp }%
\def\p@rthead{Table of Parts}%
\n@llout\p@rtwrite\p@rtfile
\def\part#1{%
   \ifpartapp%
      \xdef\p@rtname{Appendix\ \number\partcount}%
      \else%
      \xdef\p@rtname{Part\ \romannumeral\partcount}%
      \fi%
   \advance\partcount\@ne
   \begingroup\c@tset%
   \p@rttable%
   }%
\def\p@rtname{}%
\def\p@rttable#1{%
   \c@tMeoline\l@tMother
   \xdef\writeit{%
      \write\p@rtwrite{%
         \line{%
            \strut{\bf\p@rtname}\quad
            \uppercase{%
               \h@tMother#1\h@tMother
               }%
            \leaderfil\noexpand\number\p@gecount}%
         }%
      }%
   \writeit\endgroup
   \p@rtheader{#1}%
   }%
\def\p@rtheader#1{%
   \endpage%
   \llap{}\vfill%
   {\fortyss
      \centerline{\p@rtname}%
      \bigbreak%
      \centertitle{\uppercase{#1}}%
      }%
   \endpage%
   }%
\def\partout{%
   \ifnum\partcount=\z@\else
      \endpage\p@gefront
      {\bf\centertitle\p@rthead}%
      \immediate\closeout\p@rtwrite
      \input\p@rtfile
      \fi
   }%
\newcount\ch@ptercount
\newif\if@ppendix% chapter/@ppendix switch
\newwrite\ch@pterwrite
\def\ch@pterfile{chapters.psiztemp }%
\def\ch@pterhead{Table of Contents}%
\def\ch@ptertext{}%
\def\@ppendixtext{Appendix }%
%
\def\beginbody{%
   \b@dyreset
   }%
\def\b@dyreset{%
   \def\ch@ptername{}%
   \ch@pterinit\ch@pterreset
   \@ppendixfalse
   \p@geclear
   }%
\adddef\resd@c{\ch@pterclear\b@dyreset\fr@nttrue}%
\def\ch@pterinit{\ch@ptercount\@ne}%
\def\ch@pterclear{\ch@ptertot\z@\n@llout\ch@pterwrite\ch@pterfile}%
\def\ch@ptername{}%
\def\chapter{% title
   \if@ppendix\xdef\ch@ptername{\char\number\ch@ptercount\relax}%
      \let\temp\@ppendixtext
      \else   \xdef\ch@ptername{\number\ch@ptercount\relax}%
      \let\temp\ch@ptertext
      \fi\global\advance\ch@ptercount\@ne
   \ch@ptereject \ch@pterreset
   \ch@skiph
   \vbox\bgroup\begingroup\c@tset\ch@ptertable%
   }%
\def\ch@ptertable#1{%
   \@ddch@pt{#1}{\strut{\temp\ch@ptername.}\quad}\endgroup
   \vskip-\parskip
   \bf\centertitle{\temp\ch@ptername.\quad#1}\egroup
   \backpar\ch@skiph
   }%
\def\ch@ptercite#1#2{% fig, tab citation style
   \ifch@pterrenumber#1.#2\else#2\fi
   }%
\def\equ@tioncite#1#2{% eqn citation style
   \ifch@pterrenumber#1-#2\else#2\fi
   }%
\def\r@fcite#1#2{% ref citation style
   \ifr@frenumber#1.#2\else#2\fi
   }%
\def\ch@pterreset{\s@ctioninit\s@ctionreset\c@teclear}%
\def\ch@ptereject{\ifch@pterrenumber\vfill\supereject\fi}%
\def\beginappendices{\@ppendixtrue\ch@ptercount`A}%
%
% build the table of contents,etc iteratively:
%   1) put out TOC to determine its length => list of tables, figures
%      get the correct pagenumbers
%   2) put out list of tables and store its page number
%   3) put out list of figures and store its page number
%   4) put out TOC again, now using the correct page numbers for
%      list of tables  and list of figures
%
% (note: after \eject, the page number register contains the previous
%        page number)
%
\newif\iff@gt@bhead
\def\f@gt@bhead{\f@gt@bheadfalse
   \ifnum\t@btotal>\z@\f@gt@bheadtrue
      \line{\strut\t@btabhead\leaderfil\romannumeral-\t@bpagecount}%
      \fi
   \ifnum\f@gtotal>\z@\f@gt@bheadtrue
      \line{\strut\f@gtabhead\leaderfil\romannumeral-\f@gpagecount}%
      \fi
   }%
\newcount\blankcount
\def\rectoleaf{%
   \ifquadside
      \blankcount\pageno
      \divide\blankcount4\multiply\blankcount4
      \advance\blankcount-\pageno\blankcount-\blankcount
      \ifnum\blankcount=\@ne\else\hrule height\z@\endleaf\fi\lock
      \else\endpage
      \fi
   }%
\newif\ift@c
\newcount\t@cpages\t@cpages\@ne
\def\endbody{%
   \vfill\supereject% is there an alternative?
   \c@teout\endpage
   \iffrontmatter
      \immediate\closeout\ch@pterwrite
      \ifproof\else\endpage\fi
      %
      \l@stpagecount=\number\p@gecount\p@gecount=\number\t@cpagecount
      \t@bpagecount=\number\t@cpagecount\advance\t@bpagecount\t@cpages
      \f@gpagecount=\number\t@bpagecount\advance\f@gpagecount\m@ne
      \t@cfalse
      {\bf\uppercase{\centertitle{\ch@pterhead}}}\bigbreak
      \ifnum\ch@ptertot>\z@\unlock\input\ch@pterfile\lock\fi
      \iff@gt@bhead
         \ifnum\t@bpagecount=\p@gecount\else\t@ctrue\fi
         \t@bpagecount=\number\p@gecount\advance\t@bpagecount\m@ne
         \re@dback\t@btabwrite\t@btabfile\t@btabhead\t@btotal
         %
         \ifnum\f@gpagecount=\p@gecount\else\t@ctrue\fi
         \f@gpagecount=\number\p@gecount\advance\f@gpagecount\m@ne
         \re@dback\f@gtabwrite\f@gtabfile\f@gtabhead\f@gtotal
         \endleaf
         \ift@c
            \rectoleaf
            \l@stpagecount=\number\p@gecount\p@gecount=\number\t@cpagecount
            {\bf\uppercase{\centertitle{\ch@pterhead}}}\bigbreak
            \ifnum\ch@ptertot>\z@\unlock\input\ch@pterfile\lock\fi
            %
            \t@bpagecount=\number\p@gecount\advance\t@bpagecount\m@ne
            \re@dback\t@btabwrite\t@btabfile\t@btabhead\t@btotal
            %
            \f@gpagecount=\number\p@gecount\advance\f@gpagecount\m@ne
            \re@dback\f@gtabwrite\f@gtabfile\f@gtabhead\f@gtotal
            \endleaf
            \fi
         \fi
      \endleaf
      \p@gecount=\number\l@stpagecount
      \fi
   }%
% SECTION MACRO
%                            The \section macro sets the name in upper
%                            and lower case capitals, prints the
% \section{Name}%            section name and number (left adjusted)
%                            and skips the appropriate amount of space.
\newcount\s@ctioncount
\def\s@ctioninit{\global\s@ctioncount\@ne}%
\def\secskipt{\bigbreak}%
\def\s@ctionname{}%
\def\section{\xdef\s@ctionname{\ch@ptername.\number\s@ctioncount}%
   \global\advance\s@ctioncount\@ne
   \s@ctionreset
   \ch@skiph
   \vbox\bgroup\begingroup\c@tset\s@ctiontable%
   }%
\def\s@ctiontable#1{%
   \@ddch@pt{#1}{\quad\strut{\s@ctionname}\quad}\endgroup
   \vskip-\parskip
   \cp\noindent\s@ctionname\quad#1\par\egroup
   \backpar\ch@skiph\sectionindent
   }%
\def\s@ctionreset{\subs@ctioninit\subs@ctionreset}%
\let\sectionindent\relax
%
% SUBSECTION MACRO
%
% \subsection{name}%         Subsections appear with a number and
%                            with the name in slant font.
%
\newcount\subs@ctioncount
\def\subs@ctioninit{\global\subs@ctioncount\@ne}%
\def\subs@ctionname{}%
\def\subsection{% subsection macro
   \xdef\subs@ctionname{\s@ctionname.\number\subs@ctioncount}%
   \global\advance\subs@ctioncount\@ne
   \subs@ctionreset
   \ch@skiph
   \vbox\bgroup\begingroup\c@tset\subs@ctiontable%
   }%
\def\subs@ctiontable#1{%
   \@ddch@pt{#1}{\qquad\strut{\subs@ctionname}\quad}\endgroup
   \sl\noindent\subs@ctionname\quad#1\par\egroup
   \backpar\ch@skiph\subsectionindent
   }%
\def\subs@ctionreset{\subsubs@ctioninit\subsubs@ctionreset}%
\let\subsectionindent\relax
%
% SUBSUBSECTION MACRO
%
% \subsubsection{name}%         Subsubsections appear with a number and
%                            with the name in slant font.
%
\newcount\subsubs@ctioncount
\def\subsubs@ctioninit{\global\subsubs@ctioncount\@ne}%
\def\subsubsection{%
   \xdef\subsubs@ctionname{\subs@ctionname.\number\subsubs@ctioncount}%
   \global\advance\subsubs@ctioncount\@ne
   \subsubs@ctionreset
   \ch@skiph
   \vbox\bgroup\begingroup\c@tset\subsubs@ctiontable%
   }%
\def\subsubs@ctiontable#1{%
   \@ddch@pt{#1}{\quad\qquad\strut{\subsubs@ctionname}\quad}\endgroup
   \sl\noindent\subsubs@ctionname\quad#1\par\egroup
   \backpar\ch@skiph\subsubsectionindent
   }%
\def\subsubs@ctionreset{\p@ntinit\p@ntreset}%
\let\subsubsectionindent\relax
%
% Common to all macros: write into the table of contents file
%
\newcount\ch@ptertot\ch@ptertot\z@
\def\ch@skiph{\par\ifdim\lastskip<\bigskipamount
  \removelastskip\vskip\bigskipamount\fi}%
\def\backpar{\nobreak\vskip-\parskip\nobreak\nointerlineskip}%
\def\t@bcontents{% line for table of contents in table of contents
   \line{\strut\ch@pterhead\leaderfil\romannumeral-\t@cpagecount}%
   }%
\def\@ddch@pt#1#2{\c@tMeoline\l@tMother
   \xdef\next{%
      \write\ch@pterwrite{%
         \line{#2\h@tMother#1\h@tMother%
            \noexpand\leaderfil\noexpand\numorroman\p@gecount%
            }%
         }%
      }%
   \next\global\advance\ch@ptertot\@ne
   \l@tMspace
   }%
% for setting the first letter of each word uppercase: make space active
% cause next token to be \uppercase{\next}