% mail-labels.sty
%
% Label making macros for LaTeX.
% Written by Charles Karney (Karney@Princeton.EDU) 1988/10/19
%
% Modified by Allan Heydon 1/17/91 to allow specification of ``border'' size
% around label text. Also, code has been changed slightly to make
% specification of the label layout easier; documentation has been added.

% Instructions:
%
% 1) a) Specify ``mail-labels'' as an optional argument to \documentstyle.
%       Give values for the counters and dimensions described below. These
%       values should be set in the preamble, before the \makelabels command.
%    b) Alternatively, you can simply specify the name of an ``auxiliary
%       labels file'' (such as ``avery-3x11'') as an optional argument to
%       \documentstyle. This file automatically sets the values of counters
%       and dimensions for those particular labels.
% 2) a) To use in conjunction with the letter document style, specify
%       \makelabels in the preamble.
%    b) In general, labels can be produced by inserting the following in the
%       document itself:
%         \startlabels
%         \maillabel{Name1\\Address1\\Address2\\Address3}
%         \maillabel{Name2\\Address1\\Address2\\Address3}
%         etc.
%
% NOTE: ``French'' spacing is in effect, so there's no need to do anything
% special to get the space after Dr. to come out right.
%
% NOTE: You can insert vertical space via the optional argument to \\.  E.g.,
% \\[2pt].  This is sometimes nice to separate off a telephone number from
% the rest of the address.
%
% EXAMPLES
%
% An example using the ``mail-labels.sty'' file directly is:
%   \documentstyle[mail-labels]{cmu-ltr}
%   \cols=3 \rows=11
%   \labwidth=2.75in \labheight=1in
%   \colgap=0in \rowgap=0in
%   \leftmar=0in \topmar=0in
%   \hborder=.05in \vborder=.05in
%   \makelabels
%   \begin{document} ... \end{document}
%
% Here is an example using the ``auxiliary'' label file ``avery-3x11.sty'' in
% which the labels will appear in a larger font:
%   \documentstyle[avery-3x11]{cmu-ltr}
%   \makelabels
%   \def\labelfontsize{\xivpt}
%   \def\labelbaselineskip{14pt}
%   \begin{document} ... \end{document}

% Making an address book:
%
% TeX's macro facility makes it easy to create an address book.  E.g.,
% suppose you create a file address.tex containing
%     \newcommand\Kyoto{Electronics Dept.\\Kyoto University
%         \\Kyoto 606\\Japan}
%     \newcommand\GAT{General Atomic Company\\P.O. Box 81608
%         \\San Diego, CA 92138}
%     \newcommand\MaxPlanck{Max-Planck Institut f\"ur Plasmaphysik
%         \\D-8046 Garching bei M\"unchen\\Fed. Rep. of Germany}
% Then you can create labels with
%     \input{address}
%     \maillabel{Dr. H. Abe \\ \Kyoto}
%     \maillabel{Dr. P. L. Andrews \\ \GAT}
%     \maillabel{Dr. V. S. Chan \\T0-523 \GAT}
%     \maillabel{Dr. F. Leuterer \\ \MaxPlanck}
%     \maillabel{Dr. K. Borass \\NET Team \\ \MaxPlanck}

% Set the following counters and dimensions for your particular labels, or use
% an ``auxiliary'' mail labels file (such as ``avery-3x11.sty'') as described
% above.
%
\newcount\cols		% number of labels across each row on the label sheet
\newcount\rows		% number of labels down each column on the label sheet
\newdimen\labwidth	% actual physical label width
\newdimen\labheight	% actual physical label height
\newdimen\colgap	% horizontal space separating labels themselves
\newdimen\rowgap	% vertical space separating labels themselves
\newdimen\leftmar	% left margin (extra space at left of sheet)
\newdimen\topmar	% top margin (extra space at top of sheet)
\newdimen\hborder	% extra space to leave to the left of each address
\newdimen\vborder	% extra space to leave above each address

% \labelfontsize, \labelbaselineskip
%
% You may change the fontsize of the labels and the vertical space between
% lines within them by \def'ing these macros. The macro \labelfontsize should
% be set to a command to change the font size, such as \ixpt or \large; the
% macro \labelbaselineskip should be set to any legal dimension, such as 11pt
% or .2cm. The defaults are \xipt and 12pt, respectively.
%
\def\labelfontsize{\xipt}
\def\labelbaselineskip{12pt}

% other counts and dimensions
%
\newcount\thiscol	% current column number?
\newdimen\colwidth	% distance between left edges of neighbor (vert) labels
\newdimen\rowheight	% distance between top edges of neighbor (horiz) labels

% \startlabels
%
\def\startlabels{\pagestyle{empty}%
%
% Set \colwidth, \rowheight, \hsize, \vsize
\colwidth=\labwidth \advance\colwidth by \colgap
\rowheight=\labheight \advance\rowheight by \rowgap
\hsize=\cols\colwidth \vsize=\rows\rowheight
%
% Adjust dimensions to give \vborder, \hborder space around label
\advance\leftmar by \hborder \advance\labwidth by -2\hborder
\advance\topmar by \vborder \advance\labheight by -2\vborder
%
\parindent=0pt \parskip=0pt
\baselineskip=\rowheight \lineskiplimit=0pt \lineskip=0pt
\topskip=\rowheight \boxmaxdepth=0pt
\raggedright \frenchspacing \overfullrule=0pt \thiscol=0
\textheight=\vsize \textwidth=\hsize
\@colht=\textheight \@colroom=\textheight
\topmargin=-1in \advance\topmargin by \topmar
\oddsidemargin=-1in \advance\oddsidemargin by \leftmar
\evensidemargin=\oddsidemargin
\headheight=0pt \headsep=0pt \footheight=0pt \footskip=0pt
\labelfontsize\let\@texttop=\relax}

% For LaTeX letter style use
\def\mlabel#1#2{\maillabel{#2}}

% The label formatter
\def\maillabel#1{\leavevmode\hbox to \colwidth{\hss
\hbox to \labwidth{\vbox to \rowheight{\vss
\vbox to \labheight{\baselineskip=\labelbaselineskip
\raggedright\hsize=\labwidth
\let\\=\@mailcr\tolerance=10000
\pretolerance=10000 \hbadness=5000
\noindent #1\\\vfil}\vss
}\hss}\hss}\penalty0
\advance\thiscol by 1 \ifnum\thiscol=\cols\par\thiscol=0 \fi
\ignorespaces}

\def\@mailcr{\@ifnextchar[{\@mailnewline}{\mailnewline}}
\def\@mailnewline[#1]{\ifhmode\unskip\fi\vspace{#1}\mailnewline}
\def\mailnewline{\hangindent=.1\hsize\par}

\endinput

