Debian Codegraph @

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

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Module: ZzTeX Notes Facilities
4 %
5 % Synopsis: This module defines various blocks that produce "notes", such
6 % as footnotes.
7 %
8 % Author: Paul C. Anagnostopoulos
9 % Created: 28 September 1989
10 %
11 % Copyright 1989--2020 by Paul C. Anagnostopoulos
12 % under The MIT License (opensource.org/licenses/MIT)
13 %
14 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15
16 % Footnotes
17 % ---------
18
19
20 \defineblock{\footnote}{\endfootnote}{\true}{}
21
22 % The footnote parameters are used at two different times: when the
23 % \footnote macro appears, and when the page is output.
24
25 % The \referencing parameter takes the following values:
26 % 0: Produce neither a reference nor an intro number.
27 % 1: Produce an intro number, but no reference.
28 % 2: Produce both a reference and an intro number.
29
30 %~block footnote
31 % \aboveskip = glue % Space b/b above first footnote line.
32 % \setflag \abutting = flag % True if note abutts previous one.
33 % \bodyfont = {...} % Font for footnote text.
34 % \def \comptextformat {...} % Composite number text formatter.
35 % \internoteskip = glue % Extra space between footnotes.
36 % \leftindent = glue % Left indentation.
37 % \height = dimen % Maximum height on page.
38 % \interlinepenalty = penalty % Penalty between footnote lines.
39 % \def \noteintroformat {...} % Footnote intro formatter.
40 % \def \noterefformat {...} % Footnote reference formatter.
41 % \parindent = dimen % Paragraph indent.
42 % \parrag = dimen % Paragraph raggedness.
43 % \parskip = glue % Paragraph skip.
44 % \referencing = integer % How the footnote is referenced.
45 % \rightindent = glue % Right indentation.
46 % \rulecolor = {...} % Color of rule.
47 % \rulewidth = dimen % Width of rule.
48 % \ruleheight = dimen % Height of rule.
49 % \ruleshift = dimen % Horizontal shift of rule.
50 % \ruleskip = dimen % Space b/b below rule.
51 % \def \spilloverride {...} % Override parameters on spillover.
52 % \textcolor = {...} % Color of text.
53 %~end
54
55 \defineskip{\internoteskip}{0pt}
56 \definecount{\referencing}{0}
57
58 \defineinsert{\zfninsert}
59
60
61 \def \footnote {% {text}
62 \blockcantbein{\footnote}{\footnote}%
63 \beginblockscope{footnote}%
64 \global\increment \footnotedepth
65 \setflag \abutting = \false %~default with
66 \referencing = 2 %~default with
67 \interlinepenalty = \breakworse %~default hard
68 \rulecolor = {black}% %~default soft
69 \ruleshift = 0pt %~default soft
70 \def \spilloverride {}% %~default soft
71 \textcolor = {black}% %~default soft
72 \processdesign{\footnote}{}%
73 \if \posp{\referencing}%
74 \global\increment \footnotenumber
75 \setcomptext{\footnotecomptext}%
76 \else
77 \footnotecomptext = {???}%
78 \fi
79 \settaginfo{\the\footnotecomptext}{???}%
80 \if \andp{\hmodep}{\eqlp{\referencing}{2}}%
81 {\edef \zsf {\spacefactor=\the\spacefactor}%
82 \/%
83 \if \DVIWindoinuse \colorspecial{ifview color push rgb 1 0 1}\fi
84 \noterefformat
85 \if \DVIWindoinuse \colorspecial{ifview color pop}\fi
86 \zsf}%
87 \fi
88 \footnoteinsert}
89
90 \def \footnoteinsert {%
91 \the\bodyfont
92 \global\count\zfninsert = 1000
93 \global\dimen\zfninsert = \height
94 \global\skip\zfninsert = \aboveskip
95 \global\advance \skip\zfninsert by -\internoteskip
96 \global\advance \skip\zfninsert by -\ht\strutbox % of footnote text.
97 \insert \zfninsert \bgroup
98 \zpushvcontext
99 \color{\the\textcolor}%
100 \setindentation{\leftindent}{\rightindent}%
101 \setparrag{\parrag}%
102 \parfillskip = \normalparfillskip
103 \spaceskip = 0pt \xspaceskip = 0pt
104 \splittopskip = \ht\strutbox
105 \advance \splittopskip by \internoteskip
106 \splitmaxdepth = \dp\strutbox
107 \floatingpenalty = 20000\relax % Reference on same page as note.
108 \if \posp{\referencing}%
109 \noteintroformat
110 \else
111 \indent
112 \fi
113 \vbox to \splittopskip{}% % Strut in first line.
114 \bgroup
115 \aftergroup\endfootnote
116 \let \znext} % Eat open brace of footnote text.
117 % Absorb footnote text.
118 % \bgroup matches close brace.
119
120 \def \endfootnote {%
121 \if \hmodep \strut \fi % Strut in last line.
122 \endgraf
123 \unskip
124 \endcolor
125 \zpopvcontext
126 \egroup % \insert
127 \global\decrement \footnotedepth
128 \endblockscope{footnote}}
129
130 % This macro is invoked by the output routine to format footnotes.
131
132 \def \zfootnoteformat #1{% {body-depth}
133 \beginblockscope{footnote}%
134 \ruleshift = 0pt
135 \def \spilloverride {}%
136 % We used to do the \processdesign here, but that does a \processwith
137 % that can end up processing some other block's pending \with. Oops.
138 \footnotedesign \relax % \processdesign{\footnote}{}
139 \if \notp{\emptydefp{\spilloverride}}%
140 \setbox \zboxa = \vtop{\unvcopy \zfninsert}%
141 \if \dimzerop{\ht\zboxa}\spilloverride \fi
142 \fi
143 \vskip \skip\zfninsert
144 \vskip -#1\relax
145 \if \andp{\dimposp{\ruleheight}}{\dimposp{\rulewidth}}%
146 \the\bodyfont
147 \tdimena = \ruleskip
148 \advance \tdimena by -\ht\strutbox
149 \advance \tdimena by -\internoteskip
150 \vskip -\tdimena
151 \vskip -\ruleheight
152 \nointerlineskip
153 \noindent \hspace{\ruleshift}%
154 \color{\the\rulecolor}\rule{height \ruleheight depth 0pt width \rulewidth}%
155 \endcolor\par
156 \vskip \tdimena
157 \fi
158 \unvbox \zfninsert
159 \endblockscope{footnote}}
160
161 % Endnote
162 % -------
163
164
165 \defineblock{\endnote}{\endendnote}{\true}{}
166
167 % The endnote parameters are used at two different times: when the
168 % \endnote command appears, and when the \endnotes command is used
169 % to typeset the notes.
170
171 %~block endnote
172 % \setflag \abutting = flag % True if note abutts previous one.
173 % \def \comptextformat {...} % Composite number text formatter.
174 % \endnoteclass = integer % Class of endnote.
175 % \def \noterefformat {...} % Footnote reference formatter.
176 % \referencing = integer % How the endnote is referenced.
177 %~end
178
179 \definecount{\endnoteclass}{0}
180 \definetoks{\zendtoks}
181
182
183 \def \endnote {% {text}
184 \blockcantbein{\endnote}{\endnote}%
185 \beginblockscope{endnote}%
186 \global\increment \endnotedepth
187 \setflag \abutting = \false %~default with
188 \endnoteclass = 0 %~default with
189 \referencing = 2 %~default with
190 \processdesign{\endnote}{}%
191 \global\increment \endnotenumber
192 \setcomptext{\endnotecomptext}%
193 \if \andp{\hmodep}{\eqlp{\referencing}{2}}%
194 {\edef \zsf {\spacefactor = \the\spacefactor}%
195 \/%
196 \if \DVIWindoinuse \colorspecial{ifview color push rgb 1 0 1}\fi
197 \noterefformat
198 \if \DVIWindoinuse \colorspecial{ifview color pop}\fi
199 \zsf}%
200 \fi
201 \afterassignment \endendnote
202 \zendtoks =}
203
204 \def \endendnote {%
205 \edef \zendtext {\the\zendtoks}%
206 \edef \znext {\noexpand\xref{end}{\noexpand\folio}{\the\endnotecomptext}
207 {\expandafter\zdefof \meaning\zendtext\zmark}
208 {\the\divisionname,\the\endnoteclass}}%
209 \znext
210 \global\decrement \endnotedepth
211 \endblockscope{endnote}}
212
213 % Endnotes
214 % --------
215
216
217 \defineblock{\endnotes}{\endendnotes}{\false}{}
218
219 %~block endnotes
220 % \setflag \abutting = flag % True if note abutts previous one.
221 % \def \comptextformat {...} % Composite number text formatter.
222 % \endnoteclass = integer % Class of endnote.
223 % \def \noterefformat {...} % Footnote reference formatter.
224 % \referencing = integer % How the endnote is referenced.
225 %~end
226
227 \definecount{\endnotepage}{0}
228 \definetoks{\zenddivlist}
229 \definetoks{\zenddiv}
230 \definecount{\zendclass}{0}
231
232 \def \endnotes #1{% {division-list}
233 \blockcantbein{\endnotes}{\endnotes}%
234 \blockmustbein{\endnotes}{\list}%
235 \beginblockscope{endnotes}%
236 \global\increment \endnotesdepth
237 \endnoteclass = 0 %~default with
238 \processdesign{\endnote}{}% % Use endnote block's design.
239 \global\increment \endnotesnumber
240 \zenddivlist = {#1}%
241 \zxloadcomp{\xrefloadendmode}%
242 \endendnotes}
243
244 \def \endendnotes {%
245 \endgraf
246 \fakepar
247 \setlist \zendadjlist = {}%
248 \global\decrement \endnotesdepth
249 \endblockscope{endnotes}}
250
251 % This macro is called for each endnote entry in the cross-reference file.
252
253 \long\def \xrefend #1#2#3#4{%
254 \ifnum \xrefmode=\xrefloadendmode
255 \xrefendb{#1}{#2}{#3}{#4}%
256 \fi}
257
258 \long\def \xrefendb #1#2#3#4{% {page}{number}{text}{division,class}
259 \def \znext ##1,##2,##3\zmark{%
260 \zenddiv={##1}\zendclass=##2}%
261 \znext #4,0,\zmark \relax
262 \if \eqlp{\zendclass}{\endnoteclass}%
263 \edef \znext {\noexpand\inclusionlist\noexpand\zendtest
264 {\the\zenddiv}{\the\zenddivlist}}%
265 \znext
266 \if \zendtest
267 \setbox \zboxa = \hbox{\zendclass=0#1}%
268 \endnotepage = \if \dimzerop{\wd\zboxa}#1\else 0 \fi
269 \let \xrefmode = \xrefrunmode
270 \zchkendadj{#2}%
271 \item{#2}#3\par
272 \let \xrefmode = \xrefloadendmode
273 \fi
274 \fi}
275
276 % This macro allows the compositor to noninvasively adjust pages between
277 % endnotes.
278
279 \setlist \zendadjlist = {}
280
281 \long\def \endnotesadjustment #1#2{% {division.number}{commands}
282 \append{{#1}{#2}}{\zendadjlist}}
283
284 \long\def \zchkendadj #1{% {number}
285 \maplist{\zchkendadjb{#1}##1}{\zendadjlist}}
286
287 \long\def \zchkendadjb #1#2#3{% {number}{division.number}{commands}
288 \stringeql{\znext}{\the\zenddiv.#1}{#2}%
289 \if \znext #3\relax \fi}
290
291 % Margin Notes
292 % ------ -----
293
294
295 \defineblock{\marginnote}{\endmarginnote}{\true}{}
296
297 %~block marginnote Type
298 % \def \beginformat {...} % Beginning of text formatter.
299 % \bodyfont = {...} % Font for note text.
300 % \def \comptextformat {...} % Composite number text formatter.
301 % \def \endformat {...} % End of text formatter.
302 % \leftindent = glue % Left indentation.
303 % \margingutter = dimen % Gutter for note in right margin.
304 % \def \noteintroformat {...} % Note intro formatter.
305 % \def \noterefformat {...} % Note reference formatter.
306 % \parindent = dimen % Paragraph indent.
307 % \parrag = dimen % Paragraph raggedness.
308 % \parskip = glue % Paragraph skip.
309 % \position = {...} % Position (see below).
310 % \referencing = integer % How the margin note is referenced.
311 % \rightindent = glue % Right indentation.
312 % \textcolor = {...} % Color of text.
313 % \vshift = dimen % Vertical shift for note.
314 % \width = dimen % Width of text in box.
315 %~end
316
317 \definedimen{\margingutter}{0pt}
318 \definecount{\marginnotepage}{0}
319
320 \definecount{\zdivmncounter}{0}
321 \definedimen{\zmnshift}{0pt}
322 \definetoks{\zmntoks}
323 \definebox{\zmnbox}
324 \definedimen{\zmnprevdepth}{0pt}
325
326
327 \def \marginnote #1{% {type}
328 \blockcantbein{\marginnote}{\marginnote}%
329 \beginblockscope{marginnote}%
330 \global\increment \marginnotedepth
331 \global\increment \zdivmncounter
332 \whichpage{\marginnotepage}{zM:\the\divisionname-\the\zdivmncounter}%
333 \def \beginformat {}% %~default soft
334 \def \endformat {}% %~default soft
335 \leftindent = 0pt %~default soft
336 \referencing = 0 %~default soft
337 \rightindent = 0pt %~default soft
338 \textcolor = {black}% %~default soft
339 \vshift = 0pt %~default soft
340 \processdesign{\marginnote}{#1}%
341 \zparsemnpos{\the\position}%
342 \if \posp{\referencing}%
343 \global\increment \marginnotenumber
344 \setcomptext{\marginnotecomptext}%
345 \else
346 \marginnotecomptext = {???}%
347 \fi
348 \settaginfo{\the\marginnotecomptext}{???}%
349 \if \andp{\hmodep}{\eqlp{\referencing}{2}}%
350 {\edef \zsf {\spacefactor=\the\spacefactor}%
351 \/%
352 \if \DVIWindoinuse \colorspecial{ifview color push rgb 1 0 1}\fi
353 \noterefformat
354 \if \DVIWindoinuse \colorspecial{ifview color pop}\fi
355 \zsf}%
356 \fi
357 \afterassignment \endmarginnote
358 \zmntoks =}
359
360 \def \endmarginnote {%
361 \setbox \zmnbox = \vtop{%
362 \zpushvcontext
363 \color{\the\textcolor}%
364 \the\bodyfont
365 \setindentation{\leftindent}{\rightindent}%
366 \settextwidth{\width}
367 \setparrag{\parrag}%
368 \beginformat
369 \if \posp{\referencing}\noteintroformat \fi
370 \the\zmntoks
371 \endgraf
372 \endformat
373 \endcolor
374 \zpopvcontext}%
375 \marginnoteformat
376 \global\decrement \marginnotedepth
377 \endblockscope{marginnote}}
378
379 \def \marginnoteformat {%
380 \if \vmodep
381 \zmnprevdepth = \prevdepth
382 \nointerlineskip
383 \else
384 \vadjust
385 \fi
386 \bgroup
387 \moveright \zmnshift \vtop to 0pt{%
388 \vskip \vshift
389 \box \zmnbox
390 \vss
391 \tagpageonly{\uniquetag{zM}{\the\zdivmncounter}}}%
392 \egroup
393 \if \vmodep \prevdepth = \zmnprevdepth \fi}
394
395 % This macro sets up variables that specify the position of a margin note
396 % according to the \position design parameter:
397 %
398 % \ifevenpage Use next position only on even page.
399 % \ifoddpage Use next position only on odd page.
400 % \leftmargin Shift note to left margin.
401 % \outsidemargin Shift note to outside margin.
402 % \rightmargin Shift note to right margin.
403
404 \definecount{\zmnhpos}{0}
405
406 \def \zparsemnpos #1{% {options...}
407 \global\zmnhpos = 0
408 {\def \ifevenpage ##1{\if \evenp{\marginnotepage}##1\fi}%
409 \def \ifoddpage ##1{\if \oddp{\marginnotepage}##1\fi}%
410 \def \leftmargin {\global\zmnhpos=1\relax}%
411 \def \outsidemargin{\ifevenpage{\leftmargin}\ifoddpage{\rightmargin}}%
412 \def \rightmargin {\global\zmnhpos=2\relax}%
413 #1\relax}%
414 \ifcase \zmnhpos
415 \error{nomnpos}
416 {No horizontal position has been specified for a margin note}%
417 \or
418 \if \evenp{\marginnotepage}%
419 \zmnshift = -\evenlefttextmargin
420 \else
421 \zmnshift = -\oddlefttextmargin
422 \fi
423 \or
424 \calculate \zmnshift = {\textmeasure,+,\margingutter}%
425 \fi}
426
427 % This macro is invoked at the beginning of each division.
428
429 \def \zmndivinit {%
430 \global\zdivmncounter = 0\relax}
431
432 % Proof Notes
433 % ----- -----
434
435
436 \defineblock{\proofnote}{\endproofnote}{\true}{}
437
438 %~block proofnote
439 % \bodyfont = {...} % Font for note text.
440 % \evenshift = dimen % Horizontal shift for even pages.
441 % \oddshift = dimen % Horizontal shift for odd pages.
442 % \textcolor = {...} % Color of note.
443 % \vshift = dimen % Vertical shift for note.
444 % \width = dimen % Width of note.
445 %~end
446
447 \definedimen{\evenshift}{0pt}
448 \definedimen{\oddshift}{0pt}
449
450 \definecount{\zdivpncounter}{0}
451 \definecount{\zpnpage}{0}
452
453
454 \def \proofnote {% {text}
455 \blockcantbein{\proofnote}{\proofnote}%
456 \beginblockscope{proofnote}%
457 \global\increment \proofnotedepth
458 \global\increment \zdivpncounter
459 \whichpage{\zpnpage}{zP:\the\divisionname-\the\zdivpncounter}%
460 \parindent = 0pt
461 \parskip = 2pt
462 \textcolor = {black}% %~default soft
463 \vshift = 0pt %~default soft
464 \processdesign{\proofnote}{}%
465 \afterassignment \endproofnote
466 \zmntoks =}
467
468 \def \endproofnote {%
469 \zcalcpnshift
470 \setbox \zmnbox = \vtop{%
471 \zpushvcontext
472 \color{\the\textcolor}%
473 \the\bodyfont
474 \settextwidth{\width}
475 \setparrag{.4\width}%
476 \def \endpartext {}% % Prevent end-of-paragraph text.
477 \the\zmntoks
478 \endgraf
479 \endcolor
480 \zpopvcontext}%
481 \proofnoteformat
482 \long\edef \znext {\noexpand\todo{.Proof note: \the\zmntoks}}%
483 \znext
484 \global\decrement \proofnotedepth
485 \endblockscope{proofnote}}
486
487 \def \proofnoteformat {%
488 \if \vmodep
489 \zmnprevdepth = \prevdepth
490 \nointerlineskip
491 \else
492 \vadjust
493 \fi
494 \bgroup
495 \moveright \zmnshift \vtop to 0pt{%
496 \vskip -\parskip
497 \vskip \vshift
498 \box \zmnbox
499 \vss
500 \tagpageonly{\uniquetag{zP}{\the\zdivpncounter}}}%
501 \egroup
502 \if \vmodep \prevdepth = \zmnprevdepth \fi}
503
504 \def \zcalcpnshift {%
505 \if \evenp{\zpnpage}%
506 \if \negp{\evenshift}%
507 \zmnshift = \evenshift
508 \else
509 \calculate \zmnshift = {\textmeasure,+,\evenshift}%
510 \fi
511 \else
512 \if \negp{\oddshift}%
513 \zmnshift = \oddshift
514 \else
515 \calculate \zmnshift = {\textmeasure,+,\oddshift}%
516 \fi
517 \fi}
518
519 % This macro is invoked at the beginning of each division.
520
521 \def \zpndivinit {%
522 \global\zdivpncounter = 0\relax}