summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/mailing/mailing.dtx
blob: 01aabfcfd4319ddccdda3770908b9bda709cb6df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
% \iffalse meta-comment
%
% Copyright 1994-2004 Johannes Braams.  All rights reserved.
% 
% This file is part of the mailing package.
% -----------------------------------------
% 
% It may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
% 
% This work has the LPPL maintenance status "maintained".
% 
% The Current Maintainer of this work is Johannes Braams.
% 
% The list of all files belonging to the mailing package is
% given in the file `manifest.txt'.
% 
% The list of derived (unpacked) files belonging to the distribution
% and covered by LPPL is defined by the unpacking scripts (with
% extension .ins) which are part of the distribution.
% \fi
% \CheckSum{157}
%
%\iffalse
%% Copyright (C) 1999-2004 Johannes L. Braams texniek at braams.cistron.nl
%%
%%
%<*dtx>
\ProvidesFile{mailing.dtx}
%</dtx>
\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{mailing}
%<driver>\ProvidesFile{mailing.drv}
%\fi
%\ProvidesFile{mailing}
    [2004/02/20 v1.0b Send letters to multiple addresses]
%\iffalse
%<*driver>
\documentclass{ltxdoc}
\begin{document}
\pagestyle{myheadings}
\DocInput{mailing.dtx}
\end{document}
%</driver>
%\fi
%
% \GetFileInfo{mailing}
% \title{Creating a mailing}
% \author{Johannes Braams}
% \date{september 7, 1994}
% \maketitle
%
% \markboth
%      {mailing package version \fileversion\space as of \filedate}
%      {mailing package version \fileversion\space as of \filedate}
%
% \section{Introduction}
%
%    This package is intended to be used when you want to send a large
%    number of letters, all with (almost) the same text.
%
%    This package is based on the former style option \texttt{merge}
%    by Graeme McKinstry, but is is a reimplementation with a
%    different user interface.
%
% \section{The user interface}
%
%  \DescribeMacro{\addressfile}
%    The commands |\addressfile| takes a filename as its argument.
%    When the file can't be found by \LaTeX, the user will be asked to
%    supply a different name.
%
%    The address file should have the following format:
% \begin{verbatim}
%Name of addressee
%Street\\town
%Opening text of the letter
%(optional definitions)
%<blank line>
%Name of addressee
%Street\\town
%Opening text of the letter
%(optional definitions)
%<blank line>
%...
% \end{verbatim}
%    The various addresses are separated by a blank line in the file
%    (multiple blank lines in between addresses are allowed).
%    It is also possible to have multiple lines with definitions; they
%    will all be executed.
%
%  \DescribeMacro{\mailingtext}
%    The text of the mailing is entered as the argument of
%    |\mailingtext|. A difference with the original \texttt{merge.sty}
%    is that this package allows control sequences in the argument of
%    |\mailingtext|. These control sequences should then be defined in
%    the file with the address information.
%
%  \DescribeMacro{\makemailing}
%    When |\makemailing| is called the letters are produced, combining
%    the information found in the address file with the text of the
%    mailing. 
%
% \StopEventually{}
%
%  \section{The implementation}
%
%  \subsection{User interface}
%
%  \begin{macro}{\addressfile}
%    The argument to |\adressfile| is the name of the file with the
%    address information.
%    \begin{macrocode}
\newcommand{\addressfile}[1]{%
  \def\M@filename{#1}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\mailingtext}
%    The argument to this macro contains the entire text of the
%    mailing. The text may contain control sequences to be able to
%    make variations in the text.
%    \begin{macrocode}
\long\def\mailingtext#1{\global\mailing@text={#1}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\makemailing}
%    The command |\makemailing| will produce the mailing, reading
%    addresses, openings and optional definitions of variable text
%    parts from an external file.
%    \begin{macrocode}
\def\makemailing{%
  \M@openadrfile
  \loop
    \read@info
    \if@notready
      \begin{letter}{\M@toname\\\M@toaddress}%
        \opening{\M@opening}%
        \vskip\baselineskip
        \the\mailing@text
      \end{letter}
    \fi
    \if@notready
  \repeat}
%    \end{macrocode}
%  \end{macro}
%
%  \subsection{Allocations}
%
%  \begin{macro}{\M@adrfile}
%    We need to allocate an input stream for the file with the address
%    information. 
%    \begin{macrocode}
\newread\M@adrfile
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\mailing@text}
%    The contents of the letter are stored in a token register
%    \begin{macrocode}
\newtoks\mailing@text
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\if@notready}
%    A switch which indicates if the file |\M@adrfile| has been
%    exhausted. 
%    \begin{macrocode}
\newif\if@notready
\newif\if@notemptyoreof
%    \end{macrocode}
%  \end{macro}
%
%  \subsection{Internal macros}
%
%  \begin{macro}{\M@openadrfile}
%    The macro |\M@openadrfile| tries to open |\M@filename|. It that
%    doesn't succeed it asks the user to supply a new name. This is
%    done untill a file is found.
%    \begin{macrocode}
\def\M@openadrfile{%
  \openin\M@adrfile\M@filename\relax
  \ifeof\M@adrfile
    \loop
      %\PackageWarning{mailing}{I can't find the file \M@filename}
      \typeout{I can't find the file \M@filename!}
      \closein\M@adrfile
      \typein[\M@filename]{Enter a new name}
      \openin\M@adrfile\M@filename
      \ifeof\M@adrfile
    \repeat
  \fi}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\read@info}
%    The macro |\read@info| takes care of the reading of all the
%    information from |\M@adrfile|, needed to format another letter.
%    \begin{macrocode}
\def\read@info{%
  \skip@empty@lines
%    \end{macrocode}
%    The macro |\skip@empty@lines| leaves the non-empty line it found
%    in |\M@lines|. If it found an end of file condition the
%    |\if@notready| flag will be set to |\iffalse|.
%    \begin{macrocode}
  \if@notready
    \let\M@toname\M@line
    \read\M@adrfile to\M@toaddress
    \read\M@adrfile to\M@opening
    \test@eof
    \if@notready\read@defs\fi
  \fi
  }
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\read@defs}
%    Reads definitions of control sequences from the file |\M@adrfile|
%    until either an empty line is found or the end of file is
%    reached. Each line is stored in a control sequence and it is
%    executed after all definitions are read.
%    \begin{macrocode}
\def\read@defs{%
  \def\M@defns{}%
  {\loop
    \endlinechar=-1
    \read\M@adrfile to\M@line
    \endlinechar=`\^^M
%    \end{macrocode}
%    We need to get the expansion of |\M@line| into the definition of
%    |\M@defns|, not |\M@line| itself. Therefore |\M@line| is expanded
%    before |\M@defns|.
%    \begin{macrocode}
    \expandafter\toks@\expandafter\expandafter
      \expandafter{\expandafter\M@defns\M@line}%
    \xdef\M@defns{\the\toks@}%
    \test@emptyoreof
    \if@notemptyoreof
    \repeat}%
  \M@defns
  }
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\test@eof}
%    The macro |\test@eof| tests the status of of the input file. 
%    \begin{macrocode}
\def\test@eof{%
  \ifeof\M@adrfile
    \@notreadyfalse
  \else
    \@notreadytrue
  \fi}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\test@emptyoreof}
%    The macro |\test@emptyoreof| checks whether we reached an empty
%    line \emph{or} the end of the file.
%    \begin{macrocode}
\def\test@emptyoreof{%
  \@notemptyoreoftrue
  \ifx\M@line\@empty
    \global\@notemptyoreoffalse
  \fi
  \ifeof\M@adrfile
    \global\@notemptyoreoffalse
    \global\@notreadyfalse
  \fi}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\skip@empty@lines}
%    This macro skips empty lines until it finds either a non-empty
%    line or the end of the file. If necessary it sets the
%    |\if@notready| flag. The last line read is left in |\M@line|.
%    \begin{macrocode}
\def\skip@empty@lines{%
  {\loop
    \endlinechar=-1
    \ifeof\M@adrfile
      \global\@notreadyfalse
      \@tempswafalse
    \else
      \global\@notreadytrue
      \global\read\M@adrfile to\M@line
      \ifx\M@line\@empty
        \@tempswatrue
      \else
        \@tempswafalse
      \fi
    \fi
    \if@tempswa
    \repeat}%
  }
%    \end{macrocode}
%  \end{macro}
%
% \Finale
\endinput