Debian Codegraph @

texmf-dist/doc/generic/formlett/user_manual.tex

raw
1 % USER MANUAL in Plain TeX
2
3 \input formlett.sty
4
5 % FONTS
6 \font\hbold=cmbx10 at 17.28pt
7 \font\lbold=cmbx10 at 14.4pt
8 \font\bbold=cmbx10 at 12pt
9 \font\small=cmr8
10 \font\tiny=cmr5
11 \font\stt=cmtt9
12 \catcode`\@=11\relax
13 %
14 %
15 %
16 % OTHER MACROS
17 %
18 \catcode`\~=11\relax \def\t{{\tt ~}}
19 \catcode`\~=\active\relax
20 \catcode`\!=0\relax !catcode`!\=11!relax
21 !def!esc{\}!def!escs{\! }
22 !catcode`!\=0!relax \catcode`\!=12\relax
23 \def\rqs{\rq\ }
24 \def\LaTeX{{\rm L\kern-.36em\raise.3ex\hbox{\font\sc=cmcsc10\sc a}\kern-.15em
25 T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
26
27 % makeshift macro
28 \catcode`\^^M=13\relax%
29 \def\setraw{\bgroup\rm@ligature\set@space\set@tab%
30 \set@cr\stt\raw@chars[11][13][13][13][13]\def^^M{\strut\par}\setraw@@}%
31 \edef\temp@macro{%
32 \noexpand\long\noexpand\def\noexpand\setraw@@\noexpand##1^^M##2%
33 \esc@ unsetraw{##1##2\noexpand\egroup}}\temp@macro %
34 \catcode`\^^M=5\relax%
35
36
37 \font\ninerm=cmr9 \font\eightrm=cmr8
38 \font\ninei=cmmi9 \font\eighti=cmmi8
39 \font\ninesy=cmsy9 \font\eightsy=cmsy8
40 \font\ninebf=cmbx9 \font\eightbf=cmbx8
41 \font\ninett=cmtt9 \font\eighttt=cmtt8
42 \font\nineit=cmti9 \font\eightit=cmti8
43 \font\ninesl=cmsl9 \font\eightsl=cmsl8
44
45 \font\sixrm=cmr6
46 \font\sixi=cmmi6
47 \font\sixsy=cmsy6
48 \font\sixbf=cmbx6
49
50 \skewchar\ninei='177 \skewchar\eighti='177 \skewchar\sixi='177
51 \skewchar\ninesy='60 \skewchar\eightsy='60 \skewchar\sixsy='60
52 \hyphenchar\ninett=-1 \hyphenchar\eighttt=-1 \hyphenchar\tentt=-1
53
54 \font\tentex=cmtex10
55 \font\inchhigh=cminch
56 \font\titlefont=cmssdc10 at 40pt % titles in chapter openings
57 \font\eightss=cmssq8 % quotations in chapter closings
58 \font\eightssi=cmssqi8 % ditto, slanted
59 \font\tenu=cmu10 % unslanted te~t italic
60 \font\manual=manfnt % METAFONT logo and special symbols
61 \font\magnifiedfiverm=cmr5 at 10pt % to demonstrate magnification
62
63 \newskip\ttglue
64 \def\eightpoint{\def\rm{\fam0\eightrm}% switch to 8-point type
65 \textfont0=\eightrm \scriptfont0=\sixrm \scriptscriptfont0=\fiverm
66 \textfont1=\eighti \scriptfont1=\sixi \scriptscriptfont1=\fivei
67 \textfont2=\eightsy \scriptfont2=\sixsy \scriptscriptfont2=\fivesy
68 \textfont3=\tenex \scriptfont3=\tenex \scriptscriptfont3=\tenex
69 \textfont\itfam=\eightit \def\it{\fam\itfam\eightit}%
70 \textfont\slfam=\eightsl \def\sl{\fam\slfam\eightsl}%
71 \textfont\ttfam=\eighttt \def\tt{\fam\ttfam\eighttt}%
72 \textfont\bffam=\eightbf \scriptfont\bffam=\sixbf
73 \scriptscriptfont\bffam=\fivebf \def\bf{\fam\bffam\eightbf}%,
74 \tt \ttglue=.5em plus.25em minus.15em
75 \normalbaselineskip=9pt
76 \setbox\strutbox=\hbox{\vrule height7pt depth2pt width0pt}%
77 \let\sc=\sixrm \let\big=\eightbig \normalbaselines\rm}
78
79
80 %%%%%%%%%%%%%%%%
81 %%%%%%%%%%%%%%%%
82 %
83 % END OF EXTRA MACROS AND FONTS
84 %
85 %%%%%%%%%%%%%%%%
86 %%%%%%%%%%%%%%%%
87
88
89
90
91 \catcode`\@=11\relax
92 \PAGENO=1
93 \voffset=-0.3in
94
95
96 \ifx\pageno\undefined
97 \errmessage{Please run TeX if you want this article on how to use
98 <formlett.sty> to be processed as well!}
99 \fi
100
101
102 \parindent=0pt
103 \hsize=469.75499pt % the default
104 \vsize=9.6in %8.83in
105
106 \def\makefootline{\baselineskip=24pt \line{\the\footline}}
107 \footline={\lower5pt
108 \hbox to \hsize
109 {{\tenrm Jiang Z ~~~{\tensl Mail merge with the use of formlett.sty}
110 \hss \folio}}}
111
112 \leftline{\hbold Mail merge with the use of formlett.sty}
113 \bigskip
114
115
116 {\advance\leftskip by13mm \overfullrule=0pt
117 \advance\rightskip by 20mm %28mm
118 \sl
119 \noindent Zhuhan JIANG\par
120 \noindent School of Computing and Information Technology,
121 University of Western Sydney, Victoria Road, Parramatta NSW 2150, Australia.
122 {\sl ~~Email}:[email protected]\par
123 \medskip
124 \rm\smooth
125 \noindent (Last updated on 26 May 2003)\par
126 \medskip
127
128 \noindent
129 In this article, the author explains how to use a form-letter or mail
130 merge style {\tt formlett.sty}, designed for plain \TeX\space and
131 \LaTeX\space or \LaTeX2e. {\tt formlett.sty} supports different
132 parameter input methods, parameter naming and defaulting mechanism, as
133 well as facilities for previewing parameter positions and printing
134 labels. It is written for the purpose of being powerful, robust and
135 above all easy to use.\par }
136
137
138 \begincolumns
139
140 {\lbold Introduction}
141
142 \smallskip
143
144 Our purpose here is to describe a comprehensive implementation of a
145 macro system, handling form letters or mail merge under plain \TeX\space
146 or \LaTeX\space2.09 or \LaTeX2e. The main objective is to provide an
147 easy way to output many form letters with their own parameters, with or
148 without the use of multiple files. There will be a coherent and simple
149 format for putting parameters inside a form letter, with a number of
150 helping facilities for such as naming parameters and previewing their
151 positions. A minimum support for printing mailing labels is also
152 provided.
153
154
155 \medskip
156
157 The concept of macros [1] for form letters is not new: there already
158 exist macros in this connection such as {\tt merge}, {\tt textmerg} and
159 {\tt address} to name a few, see [2,3] for further details. Our stress
160 here is therefore laid on the ease to use, along with the power and the
161 robustness of the macros.
162
163 \bigskip
164
165
166 {\lbold Basic format}
167
168
169 %%%%%%%%%%%%
170 % letter top
171 %%%%%%%%%%%%
172
173 \beginletter
174 \sl
175 \hsize=3.1in\relax
176 \medskip
177 \paranames % optional
178 \tt<<FULL NAME>>;%
179 \tt<<ADDRESS-01>>;%
180 \tt<<ADDRESS-02>>;%
181 \tt<<GIVEN NAME>>;%
182 \tt<<MISSING ITEM>>;%
183 \tt<<PHONE NUMBER>>!
184 \loaddefaultparas % optional
185
186 \NOPAGENUMBERS\parindent=0pt\overfullrule=0pt
187 \paras[1]\par\paras[2]\par\paras[3]\par\medskip
188
189 Dear \paras[4],
190
191 \smallskip
192 We have been looking for
193 \paras[5] for quite a while
194 without any luck, could you help
195 us out? If so, please ring
196 \paras[6]. \par\medskip
197 Cheers!\hfill Michael\par %\vfill\eject
198 \medskip
199 \endletter
200
201 %%%%%%%%%%%%
202 % letter end
203 %%%%%%%%%%%%
204
205
206 Suppose we would like to write a form letter for mail merge in the
207 following form
208
209 \showparas
210
211 where the text inside the double arrow brackets are to be replaced by
212 the parameters specific to each individual letter. If we number these
213 parameters one by one in a single group, then the letter template will
214 be organised as
215
216 \preview
217
218 and we need just 6 parameters to personalise an individual letter. A
219 simplest example of supplying a set or a {\sl cluster} of these
220 parameters to output a merged form letter is to use
221
222 \setraw
223 \moreletter
224 Mrs L Stenson;\#1-20 Sunset Street;%
225 Hills, Norway;Louise;a Bible;220-8888!
226 \unsetraw
227
228 For more letters to be merged this way, just use again the
229 command {\tt\string\moreletter} in the above format, in which each
230 parameter is separated by a semicolon `{\tt ;}' and the whole parameter
231 cluster is ended by an exclamation mark `{\tt !}'. The actual code in
232 \LaTeX\space for making the above form letter, along with an extra
233 merged letter, may read as follows
234
235
236 \edef\setrawcount{\stt\noexpand
237 \beginrawlist[][][4][][][3.3in]{\esc@ unsetraw}}
238
239 \linecount=1\relax
240 \setrawcount
241 \documentstyle[formlett]{article}
242 \begin{document}
243 \beginletter
244 \NOPAGENUMBERS\parindent=0pt
245 \paras[1]\par\paras[2]\par
246 \paras[3]\par\medskip
247 Dear \paras[4], \par\medskip
248 We have been looking for
249 \paras[5] for quite a while
250 without any luck, could you help
251 us out? If so, please ring
252 \paras[6]. \par\medskip
253 Cheers!\hfill Michael\vfill\eject
254 \endletter
255
256 \moreletter % letter one
257 Mrs L Stenson;\#1-20 Sunset Street;%
258 Hills, Norway;Louise;a Bible;220-8888!
259 \moreletter % letter two
260 S Wales;UMIST;Manchester;Sir or Madam;%
261 a \TeX\ package{+}manual;225-9905!
262 \end{document}
263 \unsetraw
264 \rm
265
266 The line numbers in the above and later on are for quick reference only:
267 they are not a part of the program code. The letter template in lines
268 4-13 is defined by the {\tt\string\beginletter} and {\tt\string\endletter}
269 pair in line 3 and line 14, with each use of {\tt\string\moreletter}
270 generating a new merged letter. We note that command {\tt \string\paras[{\it
271 m}]} represents the $m^{th}$ merged parameter (of the first group, see
272 later), and the command {\tt\string\NOPAGENUMBERS}
273 will remove the page numbering for both \LaTeX\space and plain
274 \TeX. We also note that if one replaces lines 1-2 by
275 {\tt\string\input\space formlett.sty}, then the program will be
276 compilable under plain \TeX\space as well.
277
278
279 \medskip
280
281 Although the mail merge mechanism in the above will be sufficient for
282 most simple applications, {\tt formlett} provides in fact many more
283 features. We shall thus in the followings introduce the main features
284 one by one, from the most useful to the less likely encountered.
285
286 \medskip
287
288 To start with, we notice that in the above example there are exactly two
289 parameters to be used for the address. This is inconvenient to say the
290 least, even if we allocate say three more extra parameters for the
291 purpose. This naturally calls for the separation of the whole {\sl
292 cluster} of parameters into several {\sl groups}, so that the numbering
293 of the parameters in every group will be resynchronised. We thus use
294 {\tt\string\paras[{\it m}][{\it n}]} to denote the $m^{th}$ parameter of
295 the $n^{th}$ group of a whole cluster of merging parameters. In fact we
296 may use {\tt\string\blockparas[{\it m}][{\it n}][{\it pre}][{\it post}]}
297 to represent parameters in the $n^{th}$ group, from the $m^{th}$ to the
298 last parameter of that group, where the tokens denoted by {\it pre} and
299 {\it post} are those to be added in front and behind respectively each
300 of the legitimate parameters. The defaults for {\it pre} and {\it post}
301 are {\tt\string\noindent} and {\tt\string\par} respectively. It is
302 therefore more sensible to specify the merging parameters of the earlier
303 example via
304
305
306 %%%%%%%%%%%%
307 % letter top
308 %%%%%%%%%%%%
309
310 \beginletter
311 \sl
312 \hsize=3.1in\relax
313 \medskip
314 \paranames % optional
315 \tt<<FULL NAME>>\hfill
316 \tiny\fillzeros[4]\linecount\global\advance\linecount1\relax\par;%
317 \tt<<ADDRESS-etc>>\hfill
318 \tiny\fillzeros[4]\linecount\global\advance\linecount1\relax\par;%
319 +\tt<<GIVEN NAME>>;%
320 \tt<<MISSING ITEM>>;%
321 \tt<<PHONE NUMBER>>!
322 \loaddefaultparas % optional
323
324 \NOPAGENUMBERS\parindent=0pt\overfullrule=0pt
325 \noindent{\it\paras[1]}\par
326 \blockparas[2]\par\medskip
327
328 Dear \paras[1][2],
329
330 \smallskip
331 We have been looking for
332 \paras[2][2] for quite a while
333 without any luck, could you help
334 us out? If so, please ring
335 \paras[3][2]. \par\medskip
336 Cheers!\hfill Michael\par %\vfill\eject
337 \medskip
338 \endletter
339
340 %%%%%%%%%%%%
341 % letter end
342 %%%%%%%%%%%%
343
344 \showparas
345
346 where {\tt <<ADDRESS-etc>>} will be produced by
347 {\tt\string\blockparas[2][1]}, i.e. all the parameters of the first
348 group, starting from the 2nd parameter. We note that the missing
349 square-bracketed macro parameters for {\tt\string\blockparas} are
350 automatically provided: in fact macro parameters in {\tt formlett} are
351 systematically defaulted. Hence for example, {\tt \string\paras[1][1]}
352 is equivalent to any of the following commands
353
354 \setraw
355 \paras, \paras[1], \paras[][1],
356 \paras[1][], \paras[][]
357 \unsetraw
358
359 As for the more precise position of the merging parameters, they can
360 always be viewed via the command {\tt\string\preview}, which in this
361 case gives the following positioning
362
363 \preview
364
365 This way, the mail merge for the above letter template can also be done
366 (in plain \TeX) in the following more flexible way
367
368 \setrawcount
369 \input formlett.sty
370 \beginletter
371 \NOPAGENUMBERS\parindent=0pt
372 \noindent{\it\paras[1]}\par
373 \blockparas[2]\par\bigskip
374 Dear \paras[1][2],\par\medskip
375 We have been looking for
376 \paras[2][2] for quite a while
377 without any luck, could you help
378 us out? If so, please ring
379 \paras[3][2]. \par\medskip
380 Cheers!\hfill Michael\vfill\eject
381 \endletter \preview
382
383 \beginpilemode
384 Mrs L Stenson;\#1-20 Sunset Street
385 Hills, Norway+Louise;a Bible;220-8888!
386
387 S Wales;UMIST;Manchester+%
388 Sir or Madam;a \TeX\space
389 package{+}manual;225-9905!
390 \endpilemode
391 \end
392 \unsetraw
393 \rm
394
395
396 We note that by default we used plus sign `{\tt +}' to separate
397 different groups inside a cluster of parameters, and each cluster inside
398 a {\tt\string\beginpilemode} and {\tt\string\endpilemode} pair will
399 output a merged letter, as if it were produced by command
400 {\tt\string\moreletter} followed by that cluster of parameters.
401 The output of the first merged letter in fact reads
402
403 \moreletter
404 Mrs L Stenson;\#1-20 Sunset Street
405 Hills, Norway+Louise;a Bible;220-8888!
406
407
408 \medskip
409
410 It is often desirable to supply parameters line by line, i.e. one line
411 as one parameter. Hence the two merged letters produced by lines 25-47
412 can also be made by replacing the content included in the
413 {\tt\string\beginpilemode} and {\tt\string\endpilemode} pair (lines
414 39-46) by the following new code
415
416 \setrawcount
417 \blockmarks
418 \beginblockmode
419 Mrs L Stenson
420 \#1-20 Sunset Street
421 Hills, Norway
422 -----
423 Louise
424 a Bible
425 220-8888
426 ======
427
428 S Wales
429 UMIST
430 Manchester
431 ----
432 Sir or Madam
433 a \TeX\ package+manual
434 225-9905
435 ====
436 \endblockmode
437 \defaultmarks
438 \unsetraw
439 \rm
440
441 where obviously we have used lines with `{\tt----}' to separate groups
442 and used lines with `{\tt====}' to end a cluster of parameters. This was
443 done by the use of {\tt\string\blockmarks} which changes the group
444 delimiter `{\tt +}' and cluster delimiter `{\tt !}' into the above two
445 new ones, with the {\tt\string\defaultmarks} at the end setting them
446 back. If the whole cluster of parameters are categorised into a single
447 (first) group, then we may even use a block of consecutive nonempty
448 lines to provide the merging parameters. This is done by the use of
449 command pair {\tt\string\beginlinemode} and {\tt\string\endlinemode}.
450 Hence we may also conduct the above mail merge in for instance \LaTeX2e
451 by
452
453
454 \setrawcount
455 \documentclass{article}
456 \usepackage{formlett}
457 \begin{document}
458 \beginletter
459 \NOPAGENUMBERS\parindent=0pt
460 \paras[4]\par\blockparas[5]
461 \par\medskip
462 Dear \paras[1], \par\medskip
463 We have been looking for
464 \paras[2] for quite a while
465 without any luck, could you help
466 us out? If so, please ring
467 \paras[3]. \par\medskip
468 Cheers!\hfill Michael\vfill\eject
469 \endletter
470
471 \beginlinemode
472 Louise
473 a Bible
474 220-8888
475 Mrs L Stenson
476 \#1-20 Sunset Street
477 Hills, Norway
478
479 Sir or Madam
480 a \TeX\ package+manual
481 225-9905
482 S Wales
483 UMIST
484 Manchester
485 \endlinemode
486 \end{document}
487 \unsetraw
488 \rm
489
490 Notice that we have changed the numbering order of the parameters so
491 that the number of address lines output by {\tt\string\blockparas} is
492 more flexible.
493
494
495 \bigskip
496 {\lbold Advanced features}
497
498 The advanced features to be discussed below are mainly for the purpose
499 of (i) writing {\sl long} form letter; (ii) making {\sl many} different
500 form letters; (iii) reading mail merge parameters that are in {\sl
501 crude} ASCII form; and (iv) generating mail labels.
502
503 \medskip
504
505 It is in general better to keep the letter template, i.e. the content
506 between {\tt\string\beginletter} and {\tt\string\endletter} like those
507 in lines 4-13, in a separate file, say {\tt myletter.let}, and use
508 {\tt\string\inputletter$\{$myletter.let$\}$} to load in the letter
509 template. The advantage of this over the previously used method is that
510 the letter template can now be arbitrarily large without any risks of
511 causing computer memory problem.
512
513 \medskip
514
515 Suppose we have a collection of letter templates, we may wish to remind
516 ourselves what each parameter represents. For this purpose, we may add
517 at the top of the letter template a command {\tt\string\paranames} {\it
518 cluster}{\tt !}, where {\it cluster} is a cluster of parameters each
519 giving a name to the corresponding parameter. Command
520 {\tt\string\paranames} takes its macro parameters in the same way
521 {\tt\string\moreletter} does. After a letter template is read in,
522 command {\tt\string\showparas} will output a form letter with its
523 parameters replaced by the corresponding names. The mainly italic
524 passage containing lines 23-24, for instance, is the output of
525 {\tt\string\showparas} for the letter template in lines 102-109 given
526 explicitly later on.
527
528 \medskip
529
530 We may also use {\tt\string\paradefaults} {\it cluster}{\tt !} to
531 provide default parameters, i.e. the parameters to replace the empty or
532 not entered ones, and use {\tt\string \loaddefaultparas} inside letter
533 template to activate the parameter defaulting. We note that in general
534 commands {\tt\string\paranames} and {\tt\string\loaddefaultparas}, if
535 present, should be at the top of the letter template, with
536 {\tt\string\loaddefaultparas} below the command {\tt\string\paranames}.
537 Hence for our previous mail merge, we may re-do it via
538
539
540 \setrawcount
541 \input formlett.sty
542 \beginletter
543 \paranames % optional
544 \tt<<FULL NAME>>;\tt<<ADDRESS-etc>>;%
545 +\tt<<GIVEN NAME>>;\tt<<MISSING ITEM>>;%
546 \tt<<PHONE NUMBER>>!
547 \loaddefaultparas % optional
548 \unsetraw
549
550 \ \ \ {\it $\{$letter details given in lines 27-36$\}$}
551 \hfill{\tiny\fillzeros[4]\linecount\global\advance\linecount1\relax}
552
553 \setrawcount
554 \endletter
555 \preview \showparas
556
557 \paradefaults % optional
558 To whom this may concern
559 +Sir or Madam;something;%
560 061-225-9905!
561
562 \blockmarks
563 \beginrawblockmode{}
564 Mrs L Stenson
565 #1-20 Sunset Street
566 Hills, Norway
567 ------
568 Louise
569 a Bible
570 220-8888
571 =========
572
573 ......
574
575 Above empty line active
576 \endrawblockmode
577 \defaultmarks
578 \end{document}
579 \unsetraw
580 \rm
581
582 We note that in {\sl blockmode} with {\tt\string\blockmarks}, a line
583 with `{\tt ....}' marks the immediate start of a parameter block,
584 whether or not the lines immediately following it are empty or not. Also
585 that in {\it rawblockmode} enclosed by {\tt\string \beginrawblockmode}
586 and {\tt\string\endrawblockmode}, all characters are input in their
587 original ASCII form. In other words, the special characters for
588 \TeX\space will be ignored here.
589
590 \medskip
591
592 If the merging parameters are given by exactly $m$ lines per cluster, as
593 is often the case when they are produced by a database utility, then we
594 may use the {\tt\string\begindatamode} and {\tt\string\enddatamode} pair
595 to mark the beginning and the end of the merging parameters. For more
596 details, see the Appendix at the end.
597
598 \medskip
599
600 We may keep the letter template and the merging parameters in two
601 separate files. For instance, if we save lines 103-108 to file {\tt
602 myletter.let}, lines 39-46 or lines 48-68 to file {\tt myletter.adr},
603 then we can produce via \LaTeX\ the mail merge by
604
605 \setrawcount
606 \documentstyle[formlett]{article}
607 \begin{document}
608 \inputletter{myletter.let}
609 \showparas \preview % utility demo
610 \paradefaults To whom it may concern!
611 \inputfile{myletter.adr}
612 \beginlabels % 1st group as address
613 \inputfile{myletter.adr} % for labels
614 \endlabels
615 \end{document}
616 \unsetraw
617 \rm
618
619 where the lines 140-142 will generate the address labels using the first
620 group (as is intended here) of parameters. More precise format of
621 {\tt\string\beginlabels} and etc can be found in the Appendix.
622
623 \medskip
624
625 Another way of making labels, if no separate files for the parameters
626 are present, is to re-read the document itself and make labels instead
627 of merged form letters in the second reading. We may thus use {\tt
628 \string\input \ formlett.sty \string\initstyle\ [{\it styles}]$\{${\tt
629 article}$\}\{${\it preamble}$\}$} to replace {\tt \string\documentstyle\
630 [formlett, {\it styles}]$\{$article$\}$ {\it preamble}
631 \string\begin$\{$document$\}$}, which will be valid for \LaTeX\ but
632 ignored for \TeX\ , and will enable one to use {\tt \string\labelsquit}
633 at the end to read in the current document again with all the letters
634 there converted into the corresponding labels. Though
635 {\tt\string\initstyle} is valid for plain \TeX, \LaTeX2.09 as well as
636 \LaTeX2e, {\tt\string\initclass} will generate
637 {\tt\string\documentclass} instead of {\tt\string\documentstyle} when
638 \LaTeX2e is the processing environment. If you only want to execute
639 certain commands the first time round (i.e. before {\tt
640 \string\labelsquit} re-reads the file again), use {\tt
641 \string\firstread$\{${\it commands}$\}$} for this purpose. For more
642 detailed use and examples, read the {\sl programmer's document} attached
643 to the style file {\tt formlett.sty} and the example files it generates.
644 In fact, many details and extra features that are not contained in this
645 article may be found there.
646
647 \medskip
648
649 We already noted that if a form letter is large, we have to use
650 {\tt\string\inputletter} to load in the template. However, it is often
651 still desirable to keep everything inside a single file, while allowing
652 it to make new (scratch) files when it is being compiled. We may thus
653 use for example
654
655 \setraw
656 \beginfile{myletter.let}
657 \unsetraw
658
659 \ \ \ {\it $\{$letter template of lines 103-108$\}$}
660
661 \setraw
662 \endfile
663 \unsetraw
664 \rm
665
666 to create a letter template file {\tt myletter.let}. Likewise, the
667 merging parameters can be saved to another run-time created file {\tt
668 myletter.adr}.
669
670
671 \medskip
672
673 We have so far only used the default delimiters `{\tt ;}', `{\tt +}' and
674 `{\tt !}' to separate single, group and cluster of parameters, with
675 temporary change via {\tt\string\blockmarks} to `{\tt ....}', `{\tt
676 ----}' and `{\tt ====}' respectively. However we may change the
677 delimiters to any characters by {\tt
678 \string\delimiters$\{S\}\{G\}\{C\}$}, where $S$, $G$ and $C$ are the
679 tokens to delimit single, group and cluster of parameters respectively,
680 and change the delimiters back to the default by
681 {\tt\string\defaultmarks} or equivalently by
682 {\tt\string\delimiters$\{$;$\}\{$+$\}\{$!$\}$}.
683
684 \medskip
685
686
687 To conclude this section, let us finally look below at an `ideal' and
688 `finished' mail merge application code,. It is currently in a form
689 compilable under \LaTeX2e, and is also valid for plain \TeX\space if the
690 first three lines (lines 144-146) are removed.
691
692 \setrawcount
693 \documentclass{article}
694 \usepackage{formlett} % LaTeX2e
695 \begin{document}
696
697 %%%% MAKE file scr@[email protected]
698 \beginfile{scr@[email protected]} % letter content
699 \paranames <<name>>;<<address>>+<<items>>!
700 \loaddefaultparas
701 \parindent=0pt\blockparas\bigskip\bigskip
702 Dear \paras, \par\bigskip
703 This part is typically the letter content.
704 It now displays all the items in the 2nd
705 parameter group. They are \par
706 \blockparas[][2] \vfill\eject
707 \endfile
708
709 %%%% MAKE file scr@[email protected]
710 \beginfile{scr@[email protected]} % address file
711 \blockmarks
712 \beginblockmode
713 T Teng
714 UMIST
715 Manchester M60 1QD
716 =====
717
718 Z Jiang
719 UNE
720 Armidale NSW 2351
721 Australia
722 ------
723 Email: [email protected]
724 =====
725 \endblockmode
726 \defaultmarks
727 \endfile
728
729 % MAIN BODY
730 \paradefaults To Whom It May Concern
731 +No further info available{!}!
732 \inputletter{scr@[email protected]}
733 \inputfile{scr@[email protected]}% for letters
734 \beginlabels
735 \inputfile{scr@[email protected]}% for labels
736 \endlabels
737 \end{document}
738 \unsetraw
739 \rm
740
741 We note that if we replace lines 144-146 by {\tt\string\input\space
742 formlett.sty \string\initstyle$\{\}\{\}$}, then the mail merge can be
743 processed by either plain \TeX\space or \LaTeX\space (including
744 \LaTeX2e). It is likewise if {\tt\string\initstyle} in the replaced
745 line is replaced furthermore by {\tt\string\initclass}, except that now
746 the native \LaTeX2e environment is preserved, when applicable, rather
747 than turning it into the compatibility mode of \LaTeX2.09.
748
749 \bigskip
750 {\lbold Programmer's tips}
751
752 \smallskip
753
754 First we note that all the macro parameters that are to appear inside
755 square brackets of {\tt formlett}'s commands are defaulted, just like
756 how {\tt\string\paras[$m$][$n$]} is defaulted earlier on. The actual
757 default values can be found in the Appendix.
758
759 \medskip
760
761 For those wizard users who want to do everything their own way, we point
762 out that if for instance the 3rd letter parameter of the 2nd group of a
763 cluster is given as {\tt<A>}, then {\tt \string\LET2*3\t} will contain
764 {\tt \string\b@group \string\relax {\tt<A>}\string\e@group} right after
765 a cluster is read in. {\tt \string\DEF2*3\string~}, on the other hand,
766 contains the corresponding default parameter in the same fashion.
767 Furthermore, the command {\tt\string\checkparas[$m$][$n$]$\{$LET$\}$}
768 will copy the content of {\tt\string\paras[$m$][$n$]}, minus the
769 `wrapping' extra tokens {\tt\string\b@group\string\relax} and
770 {\tt\string\e@group}, to {\tt\string\cachedata} and set
771 {\tt\string\ifemptyparas} to true or false depending on whether the
772 content is empty or not. This way, a user may even change the
773 characteristics of his letter template by first testing the content of
774 the supplied individual parameters. However, we note that if {\tt\string
775 \loaddefaultparas} is executed, then the {\tt LET} array, when some of
776 its elements are not supplied, will contain the corresponding elements
777 of the {\tt DEF} array. Hence care must be exercised under such
778 circumstances, when interpreting the {\tt\string\cachedata} generated by
779 {\tt\string\checkparas[$m$][$n$]$\{$LET$\}$}. If necessary, we may use
780 {\tt\string\delparadefaults} to delete current default parameter array
781 {\tt DEF} so as to conduct {\tt\string\checkparas$\{$LET$\}$} more
782 precisely.
783
784 \medskip
785
786 There are also a number of generic macro utilities in {\tt formlett},
787 including a user stack and a multi-dimensional array mechanism.
788
789 \medskip
790
791 {\tt formlett} was written for all \TeX\space dialects, its format is
792 thus more close to that of plain \TeX. In fact, we deliberately avoided
793 mixing up {\tt formlett} with the standard letter environment of \LaTeX.
794 This is largely due to the fact that the limited facilities of
795 \LaTeX\space letter environment are easy to come by anyway, and are not
796 really worth writing buckled code to make {\tt formlett} a type of
797 extension of the environment. Nevertheless, one can still use the letter
798 environment of \LaTeX\space inside the form letter template. Besides,
799 the applicability of {\tt formlett} is not restricted for making form
800 {\sl letters}; it can also be used to merge other type of articles or
801 passages.
802
803
804
805
806 \bigskip
807 {\lbold References}
808
809 \smallskip
810 {\parindent=2em
811 \item{[1].} Knuth D E, {\sl The \TeX book}, Reading, Mass.,
812 Addison-Wesley, 1992. \par
813 \item{[2].} Piff M, Text merges in \TeX\ and \LaTeX, {\sl TUGboad},
814 13(4):518, 1993. \par
815 \item{[3].} Damrau J and Wester M, Form letters with 3-across
816 labels capacity, {\sl TUGboat}, 13(4):510, 1991.
817 \par
818 }
819
820
821
822
823 \penalty -50\bigskip
824
825 {\lbold Appendix}
826
827
828
829 \smallskip
830
831
832 In the followings, we give a brief summary of the main commands given by
833 {\tt formlett} version 2.1.
834
835 \medskip
836
837 Let $m$ and $n$ be numbers, $p$, $q$ and $r$ be dimensions, $A$,
838 $B$, $S$, $G$, $C$ and $T$ be tokens, and $X$ be a box.
839 Furthermore, we shall denote by $R$ a full set of letter
840 parameters ended by \lq{\tt !}\rq, with \lq{\tt;}\rqs separating
841 parameters inside a same group and \lq{\tt+}\rqs separating
842 different parameter groups. We moreover denote $R$ by $F$, when
843 \lq{\tt ; + !}\rqs there can be replaced by \lq$S$ $G$ $C$\rqs
844 respectively if {\tt \string\delimiters$\{S\}\{G\}\{C\}$} is
845 issued. In the commands tabulated below, the macro parameters
846 contained in squared brackets support default. In particular, the
847 defaults are $m$={\tt 1}, $n$={\tt 1}, $p$={\tt 8truecm},
848 $q$={\tt 1.5em}, $r$={\tt 3pt}, $A$={\tt\string\noindent} and
849 $B$={\tt\string\par}.
850
851
852
853 \newdimen\tempdimone
854 \newdimen\tempdimtwo
855 \tempdimone=\hsize
856 \advance\tempdimone by-0.2pt
857 \tempdimtwo=\hsize
858 \advance\tempdimtwo by-1.8in
859 \def\hruler{\hrule width \tempdimone}
860 \long\def\entry#1#2{%
861 \par\hbox to \tempdimone{\noindent
862 \vrule~\textbox[1.7in]{#1}~\hss
863 \vrule~\textbox[\tempdimtwo]{\raggedright#2}~\vrule}%
864 \par}
865
866 \long\def\longentry#1#2#3{%
867 \par\hbox to \tempdimone{\noindent
868 \vrule~\textbox[3in]{#1}~\hss~\vrule}\par
869 {\kern-8pt \advance\tempdimtwo0.10in
870 \vrule width1.7in height0pt \vrule width\tempdimtwo height 0.4pt \par
871 \kern-3pt}
872 \entry{#2}{#3}}
873
874 \long\def\Longentry#1#2#3{%
875 \par\hbox to \tempdimone{\noindent
876 \vrule~\textbox[3in]{#1}~\hss~\vrule}\par
877 {\advance\tempdimtwo0.08in\kern-1pt
878 \vrule~\hfill\vrule width \tempdimtwo height 0.4pt \vrule\par
879 \kern-2.5pt}%
880 \entry{#2}{#3}}
881
882
883
884 \bigskip %\bigskip
885 \penalty-1000 \vskip 0pt plus4in
886
887 {\eightpoint
888 \nointerlineskip\parskip=0pt
889
890 \hruler
891 \entry{{\tt\string\paras[$m$][$n$]}}%
892 {$m^{th}$ parameter of $n^{th}$ group }%
893
894 \entry{{\tt\string\blockparas[$m$][$n$][$A$][$B$]}}%
895 {$m^{th}$ to the last parameter of $n^{th}$ group, each
896 preceded by $A$ and followed by $B$, wrapped by $\{$\penalty
897 1000$\}$ if
898 $B$={\tt\string\relax}}
899
900 \entry{{\tt\string\addressparas[$m$][$n$][$p$][$q$]}}%
901 {$m^{th}$ to the last parameter of $n^{th}$ group, each put
902 into a box of width $p$ with indent $q$ for wrapped portions}
903
904
905 \entry{{\tt\string\loaddefaultparas}}%
906 {fill empty parameters with defaults}
907
908 %\hruler \penalty-1000
909 \hruler
910
911
912 \entry{{\tt\string\checkparas[$m$][$n$]$\{T\}$}}%
913 {$m^{th}$ parameter of $n^{th}$ group copied to {\tt\string\cachedata};
914 {\tt\string\ifemptyparas} is true if element is empty; $T$ is often
915 {\tt LET} or {\tt DEF}}%
916
917
918 \hruler
919
920
921 \entry{{\tt\string\moreletter\ $F$}}%
922 {use parameters $F$ to output a new letter}
923
924
925 \entry{{\tt\string\paranames\ $R$}}%
926 {use $R$ as parameter names}
927
928 \entry{{\tt\string\paradefaults\ $R$}}%
929 {use $R$ as default parameters}
930
931 \entry{{\tt\string\delparadefaults}}%
932 {delete default parameters}
933
934 \hruler
935
936
937 \entry{{\tt\string\delimiters$\{S\}\{G\}\{C\}$}}%
938 {use $S$, $G$, $C$ as delimiters}
939
940
941 \entry{{\tt\string\defaultmarks}}%
942 {use \lq{\tt ; + !}\rqs as delimiters}
943
944
945 \entry{{\tt\string\blockmarks}}%
946 {use \lq{\tt ....}\rq, \lq{\tt ----}\rq, \lq{\tt ====}\rqs as delimiters}
947
948 %\hruler \penalty -1000
949 \hruler
950
951 \entry{{\tt\string\preview}}%
952 {highlight parameter positions}
953
954 \entry{{\tt\string\showparas}}%
955 {display parameter names, if any}
956
957 \hruler
958
959
960 \entry{%
961 $\left\{\matrix{ \hbox{\tt\string\beginfile[$T$]$\{{\it
962 file.ext}\}$}\cr
963 \hbox{\tt\string\endfile\ \ \ \ \ \ \ \ \ \ \ \ \ }\cr}\right.$\par
964 \ \ \ {\tiny }}%
965 {write text verbatim to file {\it file.ext} (empty implies {\tt
966 scr@[email protected]}), nonempty $T$ replaces {\tt
967 \string\endfile} to mark last full line}
968
969
970
971 \entry{{\tt\string\inputletter$\{file.ext\}$}}%
972 {input letter content}
973
974 \entry{{\tt\string\inputfile$\{file.ext\}$}}%
975 {input $file.ext$}
976
977 \hruler \penalty -5000 %\vskip0pt plus 1cm
978 \hruler
979
980
981 \entry{%
982 $\left\{\matrix{ \hbox{\tt\string\beginletter}\cr
983 \hbox{\tt\string\endletter~~}\cr}\right.$ }%
984 {delimiters for letter content (template)}
985
986 \entry{%
987 $\left\{\matrix{ \hbox{\tt\string\beginpilemode}\cr
988 \hbox{\tt\string\endpilemode~~}\cr}\right.$ }%
989 {normal letter parameters cluster-wise}
990
991
992 \entry{%
993 $\left\{\matrix{ \hbox{\tt\string\beginblockmode}\cr
994 \hbox{\tt\string\endblockmode~~}\cr}\right.$ }%
995 {for line-by-line blocks of parameters, empty lines active
996 within each cluster}
997
998
999 \entry{%
1000 $\left\{\matrix{ \hbox{\tt\string\beginlinemode}\cr
1001 \hbox{\tt\string\endlinemode~~}\cr}\right.$ }%
1002 {for line-by-line parameters, empty lines delimit clusters}
1003
1004 \hruler \penalty-1000
1005 %\hruler
1006
1007 \entry{%
1008 $\left\{\matrix{ \hbox{\tt\string\beginrawblockmode$\{T\}$}\cr
1009 \hbox{\tt\string\endrawblockmode\ \ \ \ \ }\cr}\right.$ }%
1010 {raw text mode; nonempty $T$ replaces {\tt\string\endrawblockmode}
1011 to mark end}
1012
1013
1014 \entry{%
1015 $\left\{\matrix{ \hbox{\tt\string\beginrawlinemode$\{T\}$}\cr
1016 \hbox{\tt\string\endrawlinemode\ \ \ \ \ \ }\cr}\right.$ }%
1017 {raw text parameters and active spaces etc}
1018
1019 \entry{%
1020 $\left\{\matrix{ \hbox{\tt\string\begindatamode[$T$]$\{m\}$}\cr
1021 \hbox{\tt\string\enddatamode\ \ \ \ \ \ \ \ }\cr}\right.$ }%
1022 {$m$ raw text lines for one form letter}
1023
1024
1025 %\hruler \penalty-2000
1026 \hruler
1027
1028
1029 \entry{{\tt\string\PAGENO=1}}%
1030 {page number reset to 1}
1031
1032
1033 \entry{{\tt\string\NOPAGENUMBERS}}%
1034 {no page numbers}
1035
1036
1037 \entry{{\tt\string\textbox[$p$]$\{text\}$}}%
1038 {$text$ into box of width $p$}
1039
1040
1041 \entry{{\tt\string\boxmore[$r$]$\{X\}$}}%
1042 {add borderline to box $X$ at a distance $r$}
1043
1044
1045 \entry{{\tt\string\addressbox[$p$][$q$]$\{text\}$}}%
1046 {$text$ into box of width $p$, with wrapped options indented
1047 by $q$}
1048
1049
1050 \hruler
1051
1052 \Longentry{%
1053 $\left\{\matrix{ \hbox{\tt\string\beginlabels
1054 [$a$][$b$][$c$][$d$][$e$][$f$]}\cr
1055 \hbox{\tt\string\endlabels\hskip3cm}\cr}\right.$ }%
1056 {\strut\par{\sl defaults:}\everypar={\hbox{\ \ \ }}\par\par
1057 $a$={\tt 20pt}, \par $b$={\tt\string\tt\string\raggedright},
1058 \par $c$={\tt1}, $d$={\tt1}, \par
1059 $e$={\tt2.6in}, $f$={\tt2em}}%
1060 {form letters become labels: address taken from $c^{th}$ to
1061 last parameter of $d^{th}$ group, with width $e$, indent
1062 $f$, borderspace $a$ and font toks $b$}
1063
1064 \hruler
1065
1066
1067 \entry{{\tt\string\firstread$\{T\}$}}%
1068 {toks $T$ will not be read if the file is re-read via {\tt
1069 \string\labelsquit}}
1070
1071
1072 \entry{{\tt\string\initstyle[$a$]$\{b\}\{c\}$}}%
1073 {initiation for {\tt\string\labelsquit},with styles $a$,
1074 documentstyle $b$ and preamble $c$}
1075
1076
1077 \entry{{\tt\string\initclass[$a$][$o$]$\{b\}\{c\}$}}%
1078 {similar to {\tt\string\initstyle} ($o$ is \LaTeX2e options),
1079 but retains native \LaTeX2e when applicable}
1080
1081
1082 \hruler \vskip0.5pt
1083 \Longentry{%
1084 $\matrix{\hbox{\tt \string\labelsquit
1085 [$a$][$b$][$c$][$d$][$e$][$f$]$\{$\it file.ext$\}$}\cr
1086 \hbox{}\cr}$}%
1087 {\strut\par{\sl defaults:}\everypar={\hbox{\ \ \ }}\par\par
1088 see that for {\tt\string\beginlabels}}
1089 {quit after converting letters to labels by reading the current
1090 document or {\it file.ext}}
1091
1092 \hruler
1093
1094 }
1095
1096 \footline={\lower5pt
1097 \hbox to \hsize
1098 {{\rm Jiang Z ~~~{\sl Mail merge with the use of formlett.sty}
1099 \hss {\sl $\bullet$End of Document$\bullet$}
1100 \hss \folio}}}
1101
1102
1103 \vrule height2.9in width0pt depth0pt
1104 \endcolumns
1105 \vfill\eject
1106
1107
1108
1109 \end{document}
1110
1111
1112
1113