Debian Codegraph @

texmf-dist/tex/generic/midnight/labels.tex

raw
1 \ifx\LABELS\relax\endinput\else\let\LABELS=\relax\fi % \input only once
2 %
3 % labels.tex: Macros to print address labels (and bulk letters).
4 % version: 1.0 release: 24 October 1991
5 %
6 % copyright (c) 1991 Marcel R. van der Goot
7 % You can use these macros to typeset documents. You may
8 % distribute this file freely, provided that you also distribute
9 % the accompanying documentation.
10 % You may make changes to this file, or extract portions
11 % of it for inclusion in other files, provided that
12 % (1) you change the name of the file;
13 % (2) you give proper credit and include copyright
14 % information where applicable;
15 % (3) explain how an unchanged version can be obtained; and
16 % (4) document the usage of your macros/changes (if usage
17 % of your macros is not worth documenting, they must not
18 % be worth using).
19 % You are not allowed to use the name ``Midnight Macros'' for
20 % any changed files.
21 % The above rules for making changes do not apply where it
22 % is explicitly noted in this file that something can be changed
23 % to conform to your local installation.
24 %
25 % USAGE:
26 % See the file labels.doc
27 % You need Midnight/dolines.tex and Midnight/loop.tex to use these
28 % macros.
29 %
30 % original: csvax.cs.caltech.edu [131.215.131.131] in pub/tex
31 % (use anonymous ftp). Also in various archives.
32 %
33 % Caltech, Pasadena --- Marcel van der Goot
34 % [email protected]
35 % Caltech 256--80
36 % Pasadena, CA 91125
37 % USA
38 % (818) 356--4603
39 %
40
41 % update history:
42 % version 1.0: This one.
43 % release 24 Oct 1991: I undid the change from 6 Aug 1991: Matthias
44 % Feyerabend suggested a more elegant change that has the
45 % same result (involving \the\expandafter\lbl_txt#1).
46 % release 6 Aug 1991: Dolines.tex was changed since the previous
47 % release: it now calls \everyline with a single macro rather
48 % than with the text of the line. This required a change in
49 % the creation of \lbl_txt; \addlbl_txt was added.
50 % release 14 Feb 1991: The original
51 %
52
53 %%%%%% CODE: (you don't need to read this to use the macros)
54
55 \input Midnight/dolines % CHANGE this filename to correspond to
56 % your installation
57
58 %%%%%%% Registers
59 % All user-accessible registers. Some private registers are declared
60 % later.
61 % Individual labels:
62 \newdimen\vlblsize
63 \newdimen\hlblsize
64 \newskip\vindent
65 \newskip\hindent
66 \newdimen\lbloutline
67 \newtoks\beforelbl
68 \newtoks\afterlbl
69
70 % Labels on a page:
71 \newcount\vlbls
72 \newcount\hlbls
73 \newdimen\vfirst
74 \newdimen\hfirst
75 \newdimen\vinter
76 \newdimen\hinter
77
78 % We make `_' into a letter to make macros private
79 \vlbls=\catcode`\_ % minor trick to remember old value
80 \catcode`\_=11
81
82 \newbox\lbl_ % box in which a label is constructed
83
84
85 %%%%%%% Error message
86 % If a label is too large, we give an error message. \err_dim is the
87 % excess size of the label, \lbl_txt is the text of the label. \lbl_txt
88 % is set while reading the label, so that we can report which label is
89 % too large. Depending on the value of \err_act, more action is
90 % taken: 0 --> nothing, 1 --> print label anyway, others --> print
91 % this label on \lbl_log=lblerror.tex as well. \lbl_log is closed
92 % and an appropriate message printed by \close_log.
93
94 \newdimen\err_dim
95 \newtoks\lbl_txt
96 \newcount\err_act
97 \newcount\err_cnt
98 \newwrite\lbl_log
99
100 \let\erroraction=\err_act
101
102 \def\err_lbl#1% #1 = "wide" or "high"
103 {{\global\advance\err_cnt by 1
104 \newlinechar=`\^^J
105 \immediate\write16{^^J**** Label is \the\err_dim\space too #1:}%
106 \immediate\write16{\the\lbl_txt}%
107 \ifcase\err_act
108 \or\make_lbl
109 \else\immediate\write\lbl_log{\the\lbl_txt}%
110 \fi
111 }}
112
113 \def\close_msg#1%
114 {\ifnum\err_cnt>0 \immediate\write16{#1}%
115 \fi
116 }
117
118 \def\close_log
119 {\ifcase\err_act
120 \close_msg{**** \the\err_cnt\space error(s) ****}%
121 \or \close_msg{**** \the\err_cnt\space label(s) with errors %
122 are included in the dvi file ****}%
123 \else\immediate\closeout\lbl_log
124 \close_msg{**** \the\err_cnt\space error(s): see lblerror.tex ****}%
125 \fi
126 }
127
128 %%%%%%% Reading a label
129 % Every group of lines is set in a vbox, using dolines.tex (see dolines.doc).
130 % \lbl_before corresponds to \beforelines (see dolines), etc.
131 % Every line itself is set in an hbox. The sizes of the hboxes and
132 % vboxes are not specified here, because we want to do our own checking
133 % rather than rely on TeX's checking and error messages. The computation
134 % in \lbl_before is used to position the baseline of the first line
135 % independently of the height of that line. \vindent is similar to TeX's
136 % \topskip.
137
138 \def\lbl_before
139 {\global\lbl_txt={}%
140 \setbox\lbl_=\vbox\bgroup
141 \advance\vindent by -\baselineskip
142 \ifdim\vindent<0sp \vindent=0sp \fi
143 \vskip\vindent
144 \prevdepth=0sp
145 \the\beforelbl
146 }
147
148 % #1 is always equal to `\_ln', which in turn expands to the line of text.
149 % That works fine with \hbox, but we must somehow expand \_ln first before
150 % we put it in \lbl_txt. That is what the second expandafter is for. The
151 % first expandafter is to expand \the\lbl_txt (and \_ln) before the '{' is
152 % read. Otherwise no expansion is done: TeX does not expand the tokens in
153 % the text of a token variable.
154 % --- thanks for this solution to Matthias Feyerabend.
155
156 \def\lbl_every#1%
157 {\hbox{#1}%
158 \global\lbl_txt=\expandafter{\the\expandafter\lbl_txt#1^^J}%
159 }
160
161 \def\lbl_after
162 {\the\afterlbl
163 \egroup % closes \lbl_=\vbox{...}
164 \check_lbl
165 }
166
167 %%%%%%% Making a label
168 % \check_lbl checks whether the label is not too large, and, if not,
169 % calls \make_lbl. (\make_lbl can also be called from \err_lbl.)
170 % Note that \check_lbl only checks for the natural size of the label;
171 % if \hindent or \vindent have shrink components, the label may
172 % actually fit.
173
174 \def\check_lbl
175 {\err_dim=\wd\lbl_ \advance\err_dim by \hindent
176 \ifdim\err_dim>\hlblsize
177 \advance\err_dim by -\hlblsize
178 \err_lbl{wide}%
179 \else\err_dim=\ht\lbl_ \advance\err_dim by \dp\lbl_
180 \ifdim\err_dim>\vlblsize
181 \advance\err_dim by -\vlblsize
182 \err_lbl{high}%
183 \else\make_lbl
184 \fi \fi
185 }
186
187 \def\make_lbl
188 {\setbox\lbl_=\vbox to \vlblsize{\unvbox\lbl_ \vss}%
189 \setbox\lbl_=\hbox to \hlblsize
190 {\kern -\lbloutline \vrule width\lbloutline
191 \hskip\hindent \box\lbl_ \hss
192 \vrule width\lbloutline \kern -\lbloutline
193 }%
194 \setbox\lbl_=\vbox
195 {\kern -\lbloutline \hrule height\lbloutline
196 \box\lbl_
197 \hrule height\lbloutline \kern -\lbloutline
198 }%
199 \add_to_row
200 }
201
202 %%%%%%% Making a page
203 % \lbl_out takes the label constructed in \lbl_ and adds it to the current
204 % row. If the row is full, as counted by \h_cnt, the row is added
205 % to the current page. Similarly, if \v_cnt indicates a full page,
206 % the page is shipped out. (Note: There is no interline glue between
207 % rows because of the way \unvbox does (not) affect \prevdepth.)
208 % \finish_page ships out any remaining incomplete page.
209 % \count1 is used to count the labels (this is only used to report
210 % to the user when a page is shipped out).
211
212 \newbox\lbl_page
213 \newbox\lbl_row
214 \newcount\v_cnt
215 \newcount\h_cnt
216
217 \def\add_to_row
218 {\ifnum\h_cnt=0
219 \global\setbox\lbl_row=\hbox{\kern\hfirst \box\lbl_}%
220 \else\global\setbox\lbl_row=
221 \hbox{\unhbox\lbl_row \kern\hinter \box\lbl_}%
222 \fi
223 \global\advance\h_cnt by 1 \global\advance\count1 by 1
224 \ifnum\h_cnt<\hlbls
225 \else\add_to_page \global\h_cnt=0
226 \fi
227 }
228
229 \def\add_to_page
230 {\ifnum\v_cnt=0
231 \global\setbox\lbl_page=\vbox{\kern\vfirst \box\lbl_row}%
232 \else\global\setbox\lbl_page=
233 \vbox{\unvbox\lbl_page \kern\vinter \box\lbl_row}%
234 \fi
235 \global\advance\v_cnt by 1
236 \ifnum\v_cnt<\vlbls
237 \else\shipout\box\lbl_page \global\v_cnt=0 \global\advance\count0 by 1
238 \fi
239 }
240
241 \def\finish_page
242 {\ifnum\h_cnt>0 \add_to_page \fi
243 \ifnum\v_cnt>0 \shipout\box\lbl_page \global\advance\count0 by1 \fi
244 }
245
246 %%%%%%% Typesetting labels
247 % In \setup_lbl the \bgroup is to prevent some changes from continuing
248 % after \endlabels (e.g., catcode changes). Of course, we could also have
249 % reset them to the (presumed) old values in \endlabels. And anyway,
250 % it is a rather unnecessary refinement, since it doesn't make much
251 % sence to combine typesetting labels with other things in the same
252 % TeX run. We prevent changes of \erroraction while labels are being
253 % typeset, since such changes would cause confusion with respect to
254 % the log file. (Another unnecessary refinement: if you change the
255 % action you deserve what you get.)
256 % The \hsize is set properly in case \beforelbl or \afterlbl contains
257 % horizontal material (this will be typeset as a normal paragraph).
258 % It also allows the use of \line in these token registers.
259
260 \def\catcode_lbl{\catcode`\&=12 \catcode`\#=12 }
261
262 \def\setup_lbl
263 {\vfill\supereject
264 \ifcase\err_act\or\else
265 \immediate\openout\lbl_log=lblerror.tex %<- significant space
266 \fi
267 \let\beforelines=\lbl_before \let\afterlines=\lbl_after
268 \let\everyline=\lbl_every
269 \let\finishdolines=\endlabels \def\enddolines{\endlabels}%
270 \bgroup
271 \dimen0=\hlblsize \advance\dimen0 by-\hindent
272 \hsize=\dimen0
273 \let\erroraction=\relax \err_cnt=0
274 \h_cnt=0 \v_cnt=0 \global\count1=0
275 \voffset=-1in \hoffset=-1in
276 \catcode_lbl
277 }
278
279 \def\endlabels
280 {\finish_page
281 \egroup
282 \close_log
283 }
284
285 \def\beginlabels{\setup_lbl \begindolines}
286
287 \def\labelfile#1{\setup_lbl \filedolines{#1}\endlabels}
288
289
290 %%%%%%% Typesetting bulk letters
291 % This is kept quite simple: Labels are read one by one from a file,
292 % and consist of a vbox with an hbox for each line. No extra indentations
293 % or other frills. After each label has been read, we simply \input the
294 % bulk letter. In the letter, \bulkaddress will typeset the label.
295 % Just before we input the letter, we set \end=\relax, just in case the
296 % letter ends with \bye. (This is better than setting \bye=\relax, since
297 % \bye may insert extra material.) The grouping from \filedolines will
298 % restore the original \end.
299
300 \def\bulk_before{\setbox\lbl_=\vbox\bgroup}
301 \def\bulk_every#1{\hbox{#1\strut}}
302
303 \def\bulk_after
304 {\egroup % closes \setbox\lbl_=\vbox\bgroup
305 \catcode_plain
306 \let\end=\relax
307 \input\bulk_in %
308 \vfill\supereject
309 \catcode_lbl
310 }
311
312 \def\bulkaddress{\copy\lbl_}
313
314 \def\bulk#1#2% addresses, letter
315 {\vfill\supereject
316 \edef\catcode_plain{\catcode`\noexpand\&=\the\catcode`\&%
317 \catcode`\noexpand\#=\the\catcode`\#}%
318 \let\beforelines=\bulk_before \let\afterlines=\bulk_after
319 \let\everyline=\bulk_every
320 \catcode_lbl
321 \def\bulk_in{#2}%
322 \filedolines{#1}%
323 \catcode_plain
324 }
325
326
327 %%%%%%% Initial values
328 % \errorcontextlines (exists in TeX 3.0 and later versions) is set in
329 % order to not unnecessarily confuse unexperienced users. Supposedly,
330 % the macros above don't cause errors. Any errors are most likely
331 % caused by something in \beforelines or \afterlines.
332
333 \catcode`\_=\vlbls % restore catcode
334
335 \ifx\errorcontextlines\undefined % \then old TeX version
336 \else\errorcontextlines=-1
337 \fi
338
339 \erroraction=2
340 \lbloutline=0sp
341 \beforelbl={}
342 \afterlbl={}
343
344 % The following defaults are rather arbitrary, in practice the user
345 % always has to set these values.
346 \vlblsize=5cm
347 \hlblsize=10cm
348 \vindent=1.3\baselineskip
349 \hindent=0.5cm
350
351 \vlbls=5
352 \hlbls=2
353 \vfirst=1cm
354 \hfirst=5mm
355 \vinter=2mm
356 \hinter=2mm
357
358 %%%%%%%