Debian Codegraph @

texmf-dist/tex/plain/zztex/zzblock.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Module: ZzTeX Blocks
4 %
5 % Synopsis: This module provides facilities for defining and creating
6 % element blocks.
7 %
8 % Author: Paul C. Anagnostopoulos
9 % Created: 23 August 1989
10 %
11 % Copyright 1989--2020 by Paul C. Anagnostopoulos
12 % under The MIT License (opensource.org/licenses/MIT)
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 % Block Definition
17 % ----- ----------
18
19
20 \setlist \zblocklist = {}
21
22 \def \defineblock #1#2#3#4{% {\name}{\endname}{snap?}{redefine}
23 \if \emptyargp{#4}%
24 \withname\definecount{#1depth}{0}%
25 \withname\definecount{#1number}{0}%
26 \withname\definetoks{#1comptext}%
27 \withname\gdef{#1varinit}{}%
28 \if #3\withname\declaresnapitem{#1number}\fi
29 \append{#1}{\zblocklist}%
30 \fi}
31
32 \def \resetinvcontext #1{% {\name}
33 \zdeclareeveryvcontext{\zblockvcontext{#1}}}
34
35 \def \zblockvcontext #1{% {\name}
36 \zsavevcontext{\name{#1depth}=\the\name{#1depth}%
37 \name{#1number}=\the\name{#1number}%
38 \name{#1comptext}={\the\name{#1comptext}}}%
39 \global\name{#1depth}= 0\relax
40 \global\name{#1number}= 0\relax}
41
42 % Block Utilities
43 % ----- ---------
44
45
46 \defineskip{\enclosingbaselineskip}{0pt}
47 \defineskip{\enclosingleftss}{0pt}
48 \definedimen{\enclosingparindent}{0pt}
49 \definedimen{\enclosingparrag}{0pt}
50 \defineskip{\enclosingparskip}{0pt}
51 \defineskip{\enclosingrightss}{0pt}
52
53
54 \def \beginblockscope #1{%
55 \begingroup
56 \zpushblock{#1}%
57 \enclosingbaselineskip = \baselineskip
58 \enclosingleftss = \leftskip
59 \tdimena = \leftskip
60 \advance \enclosingleftss by -\tdimena
61 \enclosingparindent = \parindent
62 \enclosingparrag = \parrag
63 \enclosingparskip = \parskip
64 \enclosingrightss = \rightskip
65 \tdimena = \rightskip
66 \advance \enclosingrightss by -\tdimena}
67
68 \def \endblockscope #1{%
69 \zpopblock{#1}%
70 \endgroup}
71
72 \def \processdesign #1#2{% {\block}{type etc.}
73 \zprocessvariant{#1}%
74 \resetnumber = {}%
75 \if \definedp{#1#2design}%
76 \name{#1#2design}\relax % \relax terminates numbers and such.
77 \else
78 \error{nodesign}{No design has been defined for the `\string#1#2' block}%
79 \fi
80 \zprocesswith
81 {\globaldefs = 1 \the\resetnumber}}
82
83 \def \inblockp #1{% {\block-name}
84 \if \posp{\name{#1depth}}\true \else \false \fi}
85
86 \def \setcomptext #1{% {\xxxcomptext}
87 \edef \znext {\comptextformat}%
88 #1= \expandafter{\znext}}%
89
90 \def \blockmustbein #1#2{% {\inner}{\outer}
91 \if \zerop{\name{#2depth}}%
92 \error{blkmustnest}{A `\string#1' must be nested in a `\string#2'}%
93 \fi}
94
95 \def \blockcantbein #1#2{% {\inner}{\outer}
96 \if \posp{\name{#2depth}}%
97 \error{blkcantnest}
98 {A `\string#1' cannot be nested inside a `\string#2'}%
99 \fi}
100
101 \def \closeifinblock #1#2{% {\block}{\endblock}
102 \if \inblockp{#1}#2\fi}
103
104 % Block Stack
105 % ----- -----
106
107
108 \setlist \zblockstack = {}
109 \setlist \zlinestack = {}
110
111 \def \zpushblock #1{%
112 \push{#1}{\zblockstack}%
113 \edef \znext {\noexpand\push{\the\inputlineno}}%
114 \znext{\zlinestack}}
115
116 \def \zpopblock #1{%
117 \pop{\zblk}{\zblockstack}%
118 \pop{\zline}{\zlinestack}%
119 \stringeql{\znext}{\zblk}{#1}%
120 \if \notp{\znext}%
121 \error{blkinvnest}{The `\string\end#1' command does not match the
122 `\zblk' block that was started on line \zline}%
123 \fi}
124
125 \def \zemptyblockstackp {\emptylistp{\zblockstack}}
126
127 % Block Variants
128 % ----- --------
129
130
131 \def \definevariant #1#2#3{% {\block}{\style}{\modifier0,\modifier1,...}
132 \if \emptyargp{#3}%
133 \error{varmod}{Between 1 and 8 modifier commands must be specified}%
134 \fi
135 \withname\definecount{#2variant}{0}%
136 \withname\xdef{#1varinit}{\name{#1varinit}\name{#2variant}=0}%
137 {\tcounta = 0
138 \zdefvarpre #2#3,\zmark
139 \if \gtrp{\tcounta}{8}%
140 \error{varmod}{Between 1 and 8 modifier commands must be specified}%
141 \fi
142 \ztoksa = \expandaftertwice{\name{\zvarcase\lcromannumeral\tcounta}}%
143 \edef \znext {\global\let \name{#2varcase}=\the\ztoksa}%
144 \znext}}
145
146 \def \zdefvarpre #1#2,#3\zmark{% \style\modifier,\modifier,...,\zmark
147 \xdef #2{\noexpand\variant{\name{#1variant}=\the\tcounta}}%
148 \increment \tcounta
149 \if \notp{\emptyargp{#3}}\zdefvarpre #1#3\zmark \fi}
150
151 \gdef \zvariant {} % Holds \stylevariant assignments.
152
153 \def \variant #1{% {\stylevariant assignment}
154 {\ztoksa = \expandafter{\zvariant}%
155 \ztoksb = {#1}%
156 \xdef \zvariant {\the\ztoksa \the\ztoksb}}%
157 \ignorespaces}
158
159 \def \zprocessvariant #1{% {\block}
160 \name{#1varinit}%
161 \zvariant \relax % \relax terminates numbers and such.
162 \gdef \zvariant {}}
163
164 \def \varcase #1{% \style
165 \name{#1varcase}#1}
166
167 \long\def \zvarcasei #1#2{% \style {var1 code}
168 \ifcase \name{#1variant}#2\else\zbadvar\fi\relax}
169 \long\def \zvarcaseii #1#2#3{% \style {var1 code}{var2 code}
170 \ifcase \name{#1variant}#2\or#3\else\zbadvar\fi\relax}
171 \long\def \zvarcaseiii #1#2#3#4{%
172 \ifcase \name{#1variant}#2\or#3\or#4\else\zbadvar\fi\relax}
173 \long\def \zvarcaseiv #1#2#3#4#5{%
174 \ifcase \name{#1variant}#2\or#3\or#4\or#5\else\zbadvar\fi\relax}
175 \long\def \zvarcasev #1#2#3#4#5#6{%
176 \ifcase \name{#1variant}#2\or#3\or#4\or#5\or#6\else\zbadvar\fi\relax}
177 \long\def \zvarcasevi #1#2#3#4#5#6#7{%
178 \ifcase \name{#1variant}#2\or#3\or#4\or#5\or#6\or#7\else\zbadvar\fi\relax}
179 \long\def \zvarcasevii #1#2#3#4#5#6#7#8{%
180 \ifcase \name{#1variant}#2\or#3\or#4\or#5\or#6\or#7\or#8\else\zbadvar\fi\relax}
181 \long\def \zvarcaseviii #1#2#3#4#5#6#7#8#9{%
182 \ifcase\name{#1variant}#2\or#3\or#4\or#5\or#6\or#7\or#8\or#9\else\zbadvar\fi\relax}
183
184 \def \setvariant #1{% \modifier
185 #1%
186 \zvariant \relax
187 \gdef \zvariant {}}
188
189 \def \zbadvar {%
190 \zzerror{Invalid value for variant}}
191
192 % Block Options
193 % ----- -------
194
195
196 \gdef \zwith {} % Holds \with parameters.
197
198
199 %~ The |\with| modifier can be used to modify specific design
200 %~ parameters for the following block. It only makes sense
201 %~ preceding block commands. Sometimes it is used with parameters
202 %~ that are specifically intended for |\with|:
203 %~ \with{\itemnumber=4} \list{number}
204 %~ Other times it is used with a parameter that needs to be
205 %~ changed for one particular block.
206 %~ \with{\advance\belowskip by -8pt} \float{figure}
207 %~ Again, be careful to use |\with| only on block commands.
208
209 \long\def \with #1{% {parameter-assignments} %^modifier
210 {\ztoksa = \expandafter{\zwith}%
211 \ztoksb = {#1}%
212 \xdef \zwith {\the\ztoksa \the\ztoksb}}%
213 \ignorespaces}
214
215 \def \zprocesswith {%
216 \zwith \relax % \relax terminates numbers and such.
217 \gdef \zwith {}}
218
219 %~ This block modifier forces a page break above the block.
220
221 \def \breakabove {% %^modifier
222 \with{\abovepenalty=\breakalways}}
223
224 %~ This block modifier forces a page break below the block.
225
226 \def \breakbelow {% %^modifier
227 \with{\belowpenalty=\breakalways}}
228
229 % Common Design Parameters
230 % ------ ------ ----------
231
232
233 % These design parameters are used by a variety of ZZTeX's blocks, so
234 % they are defined here.
235
236 % Integer parameters:
237
238 \definecount{\abovepenalty}{0} % Penalty above block.
239 \definecount{\authorlevel}{0} % Author ToC entry level.
240 \definecount{\belowpenalty}{0} % Penalty below block.
241 \definecount{\continue}{0} % Block is continued (bit 0) and/or continuation (bit 1).
242 \definecount{\difficulty}{0} % Level of difficulty of the block.
243
244 % Flag parameters:
245
246 \setflag \allowbreaks = \false % Allow page breaks in block?
247 \setflag \allowintoc = \false % Allow section in ToC?
248
249 % Dimension parameters:
250
251 \definedimen{\height}{0pt} % Height of text.
252 \definedimen{\ruleshift}{0pt} % Horizontal shift for rule.
253 \definedimen{\ruleheight}{0pt} % Height (thickness) of rule.
254 \definedimen{\rulewidth}{0pt} % Width of rule.
255 \definedimen{\topadjust}{\mindimen} % Adjustment for head at top of page.
256 \definedimen{\vshift}{0pt} % Vertical shift.
257 \definedimen{\width}{0pt} % Width of text.
258
259 % Skip (glue) parameters:
260
261 \defineskip{\aboveskip}{0pt} % Base/base skip above block.
262 \defineskip{\belowskip}{0pt} % Base/base skip below block.
263 \defineskip{\columngutter}{0pt} % Width of gutter between columns.
264 \defineskip{\interrowskip}{0pt} % Extra space between rows.
265 \defineskip{\leftindent}{0pt} % Left indentation glue.
266 \defineskip{\numbersink}{0pt} % Sinkage to section number, or
267 \defineskip{\numberskip}{0pt} % Space b/b to section number.
268 \defineskip{\parhang}{0pt} % Hanging indent for paragraph.
269 \defineskip{\rightindent}{0pt} % Right indentation glue.
270 \defineskip{\ruleskip}{0pt} % Vskip for rule.
271 \defineskip{\textsink}{0pt} % Vsink for text.
272 \defineskip{\textskip}{0pt} % Base/base skip for text.
273 \defineskip{\titlesink}{0pt} % Sinkage to section title, or
274 \defineskip{\titleskip}{0pt} % Space b/b to section title.
275
276 % Token list parameters:
277
278 \definetoks{\authortext} % Part/chapter author text.
279 \definetoks{\bodyfont} % Font for body of block.
280 \definetoks{\divisions} % List of division names.
281 \definetoks{\numberfont} % Font for block number.
282 \definetoks{\numberwordfont} % Font for block word like "chapter".
283 \definetoks{\openertext} % Part/chapter opener text.
284 \definetoks{\position} % Position of the block.
285 \definetoks{\resetnumber} % List of sequence numbers to reset.
286 \definetoks{\rulecolor} % Color of a rule.
287 \definetoks{\runners} % Running head/foot macros.
288 \definetoks{\style} % Heading style.
289 \definetoks{\textcolor} % Color of text.
290 \definetoks{\titlefont} % Font for title.
291
292 % Macro parameters:
293
294 \def \numberformat #1{} % {code} %~ Formatter for block number.
295 \def \paging {} % {code} %~ Page control commands.
296 \def \providemark #1{} % {code} %~ Provide marks for the block.
297 \def \titleformat {} % {code} %~ Formatter for title.
298
299 % The \continue Parameter
300 % --- --------- ---------
301
302
303 % The \continue parameter is set as follows:
304 % 0: neither continued nor continuation
305 % 1: continued
306 % 2: continuation
307 % 3: both continuation and continued
308
309
310 \def \continuedp {\oddp{\continue}}
311
312 \def \continuationp {\gtrp{\continue}{1}}
313
314 \def \zsetcontinue {%
315 \if \andp{\zerop{\continue}}{\continuation}%
316 \continue = 2\relax
317 \fi}
318
319 % Break Element
320 % ----- -------
321
322
323 \long\def \breakelement #1{%
324 \global\setflag \zinpar = {\hmodep}%
325 \if \zinpar \flushendpar \fi
326 #1%
327 \if \zinpar \noindent \ignorespaces \fi}