Professional Documents
Culture Documents
sty
Zhuhan JIANG
School of Computing and Information Technology, University of Western Sydney, Vic-
toria Road, Parramatta NSW 2150, Australia. Email: z.jiang@uws.edu.au
(Last updated on 26 May 2003)
In this article, the author explains how to use a form-letter or mail merge style
formlett.sty, designed for plain TEX and LaTEX or LaTEX2e.formlett.sty supports
different parameter input methods, parameter naming and defaulting mechanism, as
well as facilities for previewing parameter positions and printing labels.It is written for
the purpose of being powerful, robust and above all easy to use.
0002
Suppose we would like to write a form letter for mail
\beginletter 0003
merge in the following form
\NOPAGENUMBERS\parindent=0pt 0004
We have been looking for <<MISSING ITEM>> for without any luck, could you help 0010
quite a while without any luck, could you help us us out? If so, please ring 0011
where the text inside the double arrow brackets are 0015
individual letter. If we number these parameters Mrs L Stenson;\#1-20 Sunset Street;% 0017
one by one in a single group, then the letter template Hills, Norway;Louise;a Bible;220-8888! 0018
for the purpose. This naturally calls for the separa- \noindent{\it\paras[1]}\par 0028
every group will be resynchronised. We thus use We have been looking for 0031
\paras[m][n] to denote the mth parameter of the \paras[2][2] for quite a while 0032
nth group of a whole cluster of merging parameters. without any luck, could you help 0033
In fact we may use \blockparas[m][n][pre][post] us out? If so, please ring 0034
to represent parameters in the nth group, from the \paras[3][2]. \par\medskip 0035
mth to the last parameter of that group, where the Cheers!\hfill Michael\vfill\eject 0036
tokens denoted by pre and post are those to be added \endletter \preview 0037
in front and behind respectively each of the legit- 0038
imate parameters. The defaults for pre and post \beginpilemode 0039
are \noindent and \par respectively. It is therefore Mrs L Stenson;\#1-20 Sunset Street 0040
more sensible to specify the merging parameters of Hills, Norway+Louise;a Bible;220-8888! 0041
the earlier example via 0042
<<ADDRESS-etc>> 0024
Sir or Madam;a \TeX\space 0044
package{+}manual;225-9905! 0045
\end 0047
We have been looking for <<MISSING ITEM>> for
We note that by default we used plus sign ‘+’ to
quite a while without any luck, could you help us
separate different groups inside a cluster of parame-
out? If so, please ring <<PHONE NUMBER>>.
ters, and each cluster inside a \beginpilemode and
Cheers! Michael \endpilemode pair will output a merged letter, as
if it were produced by command \moreletter fol-
where <<ADDRESS-etc>> will be produced by lowed by that cluster of parameters. The output of
\blockparas[2][1], i.e. all the parameters of the the first merged letter in fact reads
first group, starting from the 2nd parameter. We
note that the missing square-bracketed macro pa- Mrs L Stenson
rameters for \blockparas are automatically pro- #1-20 Sunset Street Hills, Norway
vided: in fact macro parameters in formlett Dear Louise,
are systematically defaulted. Hence for example,
We have been looking for a Bible for quite a while
\paras[1][1] is equivalent to any of the following
without any luck, could you help us out? If so,
commands
please ring 220-8888.
\paras, \paras[1], \paras[][1],
\paras[1][], \paras[][] Cheers! Michael
line, i.e. one line as one parameter. Hence the a Bible 0087
two merged letters produced by lines 25-47 can also 220-8888 0088
\beginpilemode and \endpilemode pair (lines 39- \#1-20 Sunset Street 0090
46) by the following new code Hills, Norway 0091
\blockmarks 0048
0092
\beginblockmode 0049
Sir or Madam 0093
Mrs L Stenson 0050
a \TeX\ package+manual 0094
\#1-20 Sunset Street 0051
225-9905 0095
Hills, Norway 0052
S Wales 0096
----- 0053
UMIST 0097
Louise 0054
Manchester 0098
a Bible 0055
\endlinemode 0099
220-8888 0056
\end{document} 0100
====== 0057
Notice that we have changed the numbering order of
0058
the parameters so that the number of address lines
S Wales 0059
output by \blockparas is more flexible.
UMIST 0060
Manchester 0061
---- 0062
Advanced features
Sir or Madam 0063
The advanced features to be discussed below are
a \TeX\ package+manual 0064
mainly for the purpose of (i) writing long form letter;
225-9905 0065
(ii) making many different form letters; (iii) read-
==== 0066
ing mail merge parameters that are in crude ASCII
form; and (iv) generating mail labels.
\endblockmode 0067
without any luck, could you help 0079 We may also use \paradefaults cluster! to
us out? If so, please ring 0080 provide default parameters, i.e. the parame-
\paras[3]. \par\medskip 0081 ters to replace the empty or not entered ones,
Cheers!\hfill Michael\vfill\eject 0082 and use \loaddefaultparas inside letter tem-
\endletter 0083 plate to activate the parameter defaulting. We
0084 note that in general commands \paranames and
\beginlinemode 0085 \loaddefaultparas, if present, should be at the top
low the command \paranames. Hence for our pre- \showparas \preview % utility demo 0137
vious mail merge, we may re-do it via \paradefaults To whom it may concern! 0138
\tt<<PHONE NUMBER>>! 0106 where the lines 140-142 will generate the address
\loaddefaultparas % optional 0107 labels using the first group (as is intended here) of
{letter details given in lines 27-36} 0108 parameters. More precise format of \beginlabels
\endletter 0109 and etc can be found in the Appendix.
\preview \showparas 0110
0111
Another way of making labels, if no separate
\paradefaults % optional 0112
files for the parameters are present, is to re-read
To whom this may concern 0113
the document itself and make labels instead of
+Sir or Madam;something;% 0114
merged form letters in the second reading. We
061-225-9905! 0115
may thus use \input formlett.sty \initstyle
0116
[styles]{article}{preamble} to replace
\blockmarks 0117
\documentstyle [formlett, styles]{article}
\beginrawblockmode{} 0118
preamble \begin{document}, which will be valid
Mrs L Stenson 0119
for LaTEX but ignored for TEX , and will en-
#1-20 Sunset Street 0120
able one to use \labelsquit at the end to read
Hills, Norway 0121
in the current document again with all the let-
------ 0122
ters there converted into the corresponding la-
Louise 0123
bels. Though \initstyle is valid for plain TEX,
a Bible 0124
LaTEX2.09 as well as LaTEX2e, \initclass will gen-
220-8888 0125
erate \documentclass instead of \documentstyle
========= 0126
when LaTEX2e is the processing environment. If you
0127
only want to execute certain commands the first
...... 0128
time round (i.e. before \labelsquit re-reads the
0129
file again), use \firstread{commands} for this pur-
Above empty line active 0130
pose. For more detailed use and examples, read the
\endrawblockmode 0131
programmer’s document attached to the style file
\defaultmarks 0132
formlett.sty and the example files it generates.
\end{document} 0133
In fact, many details and extra features that are not
We note that in blockmode with \blockmarks, a contained in this article may be found there.
line with ‘....’ marks the immediate start of a We already noted that if a form letter is large, we
parameter block, whether or not the lines imme- have to use \inputletter to load in the template.
diately following it are empty or not. Also that However, it is often still desirable to keep everything
in rawblockmode enclosed by \beginrawblockmode inside a single file, while allowing it to make new
and \endrawblockmode, all characters are input in (scratch) files when it is being compiled. We may
their original ASCII form. In other words, the spe- thus use for example
cial characters for TEX will be ignored here. \beginfile{myletter.let}
If the merging parameters are given by exactly m {letter template of lines 103-108}
lines per cluster, as is often the case when they are \endfile
produced by a database utility, then we may use the to create a letter template file myletter.let. Like-
\begindatamode and \enddatamode pair to mark wise, the merging parameters can be saved to an-
the beginning and the end of the merging parame- other run-time created file myletter.adr.
ters. For more details, see the Appendix at the end.
We have so far only used the default delimiters
We may keep the letter template and the merging ‘;’, ‘+’ and ‘!’ to separate single, group and
parameters in two separate files. For instance, if we cluster of parameters, with temporary change via
save lines 103-108 to file myletter.let, lines 39- \blockmarks to ‘....’, ‘----’ and ‘====’ respec-
46 or lines 48-68 to file myletter.adr, then we can tively. However we may change the delimiters to
produce via LaTEX the mail merge by any characters by \delimiters{S}{G}{C}, where
\documentstyle[formlett]{article} 0134 S, G and C are the tokens to delimit single, group
\begin{document} 0135 and cluster of parameters respectively, and change