The labels document class^{∗}

Andrew D. Lewis

1998/04/03

1 Introduction

This is the documentation for the labels document class which I use for making sheets of labels. There are L^{A}TEX packages in existence for making labels, but I found them hard to use, and they also seemed to produce a sheet of identical labels, which is not always the goal.

2 Features

My labels document class has the following features:

1. The user can enter the size of the page manually for oddly sized label sheets.

2. It allows straightforward specification of the number of labels on the page by allowing the user to enter the number of rows and columns of labels.

3. The labels may be set up to be the same or the text for each label may be read from a set of numbered files. If a file is not present, the corresponding label will be left blank.

4. The position of the text inside each label may be specified globally. In addition, each label can be positioned individually.

5. Custom text may be placed on each label.

6. The labels may be optionally framed.

The rest of this documentation is devoted to explaining how to use each of the above mentioned features.

3 The User Commands

Here we explain the commands available with labels.

∗This file has version number v2.0a, last revised 1998/04/03.

3.1 Specifying Page Sizes

With labels you may specify the standard L^{A}TEX page sizes (letter, legal, A4, A5, etc.) in the usual manner by specifying global options in the \documentclass

\setpaperwidth command. If you wish to specify other sizes, use the commands \setpaperwidth \setpaperheight and \setpaperheight. These both take a single argument which is, obviously, the

width and height, respectively, of the label sheet you are using. These commands should be used in the document preamble.

3.2 Specifying the Number of Labels

The number of labels is determined by the number of rows and the number of \rows columns. These are set with the commands \rows and \columns, respectively.

\columns Each of these takes a single integer argument which does the obvious thing. These commands should appear in the document preamble and after the commands \setpaperwidth or \setpaperheight if you have used them to set the page size.

3.3 Setting the Text for the Labels

You may choose to make all the labels the same, or have each one be different. To make the labels the same, use the command \labeltext. The argument of \labeltext will be given to the L^{A}TEX command \shortstack (this is used in the L^{A}TEX picture environment), so the text should reflect this. An example of a legal argument is

    Name\\
    Address\\
    State and zip code\\

The text is left justified in the \shortstack.

If you wish to use different text for each label, then you should put the text into files names text1.tex,…, textn.tex where n is the number of labels. If a file is missing, the corresponding label will be left blank. Again, the contents of each file will be placed in a left justified \shortstack, so it should be formatted accordingly.

3.4 Positioning the Labels on the Page

The first thing to worry about is any offset on the label sheet. It is common that there will be a strip on the top and/or side of your sheet which messes up the specification of the page size. In this event, you may use the command

\pageoffset \pageoffset(dx,dy) which will shift the top left corner of the labels down by dy and to the right by dx. Note that in this case the size of the page as set by \setpaperwidth and \setpaperheight will be the size of that portion of the page which contains labels.

\offset The position of the text in the label is specified with the command \offset(xoff ,yoff ). Here xoff and yoff are numbers which give the position of the centre of the text as a fraction of the size of each label. The origin is taken to be the top left corner of the box. Thus \offset(0,0) will place the centre of the text at the top left corner of the label, \offset(0.5,0.5) will place the centre of the text in the middle of the label, and \offset(1,1) will place the centre of the text in the lower right corner of the label. Any overflow will spill over to adjacent labels (i.e., no clipping).

The command \offset should appear in the document preamble, and will specify the position for each label. If you would like to customise the location of a certain label, this is possible. Let us suppose that you wish to reposition the label whose text is in textk.tex. Then you simply make \offset(xoffloc,yoffloc) the first line in the file textk.tex. Here xoffloc and yoffloc are the offsets you would like for this label. The offsets for the other labels will remain the default which was set with the use of \offset in the document preamble.

3.5 Custom Text on Each Label

Sometimes you will want to put other text on a label other than just the address of

\everylabel the recipient (for example, your return address). To do this use the \everylabel \placetext command in conjunction with the \placetext command. The syntax would be

as follows:

    \everylabel{
    \placetext(xoff ,yoff ){text}
    }

As usual xoff and yoff specify the offset from the top left corner as a ratio of the width and height of each label, respectively. Multiple \everylabel entries are possible.

3.6 Framing the Labels

It may be desirable to frame the labels, at least to see how they look before you print them out. This may be accomplished by specifying the option frames in the \documentclass command. The option noframes is also available, and is the default.

3.7 Making the Labels

Now that you have all the parameters set up, you will need to actually make the

\makelabels labels. This is done with the command \makelabels which should appear after

the \begin{document}.

4 Demos

In the distribution are included some demonstration files. These are in the demos directory. In demos/1 identical labels are made. In demos/2 each label is different.

The final demo file, in demos/3, gives different labels and gives a few tricks as well. Namely, one of the text files is missing, and two labels are given offsets different than the default. You should be able to figure them out by looking at them. The \everylabel command is also demonstrated here.

Please send any comments and errors to: andrew@mast.queensu.ca.

5 Implementation

1 ⟨∗labels⟩

   Model after article.cls.

2

 3 \newif\if@ADL@frames
 4 \newif\if@ADL@file\@ADL@filetrue
 5 \DeclareOption{frames}{\@ADL@framestrue}
 6 \DeclareOption{noframes}{\@ADL@framesfalse}
 7 \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
 8 \ExecuteOptions{noframes}
 9 \ProcessOptions
10 \LoadClass{article}

Declare some conditional and counters, and define the macros for specifying the number of rows and columns.

11

12 \newcount\@ADL@columns
13 \newcount\@ADL@rows
14 \newcount\@ADL@numrow
15 \newcount\@ADL@numcolumn
16 \newcount\@ADL@numfile
17 \newif\if@ADL@rowsset\@ADL@rowssetfalse
18 \newif\if@ADL@columnsset\@ADL@columnssetfalse
19 \newcommand\columns[1]{\global\@ADL@columns#1\@ADL@columnssettrue
20 \if@ADL@rowsset\@ADL@setdims\fi}
21 \newcommand\rows[1]{\global\@ADL@rows#1\@ADL@rowssettrue
22 \if@ADL@columnsset\@ADL@setdims\fi}

Page formatting. Take up the whole paper with no margins. Define the \pageoffset command for user hacks to shift things to the right place.

23

24 \setlength{\textwidth}{\paperwidth}
25 \setlength{\oddsidemargin}{-1in}
26 \setlength{\marginparwidth}{0in}
27 \setlength{\marginparsep}{0in}
28 \setlength{\parindent}{0pt}
29 \setlength{\textheight}{\paperheight}
30 \setlength{\topmargin}{-1in}
31 \setlength{\headheight}{0in}
32 \setlength{\headsep}{0in}
33 \def\pageoffset(#1,#2){\addtolength{\oddsidemargin}{#1}

34 \addtolength{\topmargin}{#2}}

Commands for numerical operations.

35

36 \newcount\t@counta
37 \newcount\t@countb
38 \newcount\t@countc
39 \newcount\t@countd
40 \newcount\t@counte
41 \newcommand\@ADL@realdiv[3]{\dimen0=#1pt \t@counta=\dimen0 \dimen0=#2pt
42 \t@countb=\dimen0 \@ADL@intdiv \t@counta \t@countb #3}
43 \newcommand\@ADL@intdiv[3]{\t@counta=#1 \t@countb=#2 \ifnum \t@countb<0
44 \t@counta=-\t@counta \t@countb=-\t@countb \fi \t@countd=1
45 \ifnum \t@counta<0 \t@counta=-\t@counta \t@countd=-1 \fi
46 \t@countc=\t@counta  \divide \t@countc by \t@countb
47 \t@counte=\t@countc  \multiply \t@counte by \t@countb
48 \advance \t@counta by -\t@counte \t@counte=-1
49 \loop \advance \t@counte by 1 \ifnum \t@counte<16
50 \multiply \t@countc by 2 \multiply \t@counta by 2
51 \ifnum\t@counta<\t@countb \else \advance \t@countc by 1
52 \advance \t@counta by -\t@countb \fi \repeat
53 \divide \t@countb by 2 \ifnum \t@counta<\t@countb \advance \t@countc by 1
54 \fi \ifnum \t@countd<0 \t@countc=-\t@countc \fi
55 \dimen0=\t@countc sp \edef #3{\expandafter\c@lean\the\dimen0}}
56 \newcommand\@ADL@realadd[3]{\dimen0=#1pt \dimen2=#2pt \advance \dimen0 by
57 \dimen2 \edef #3{\expandafter\c@lean\the\dimen0}}
58 \newcommand\@ADL@realmult[3]{\dimen0=#1pt \dimen2=#2\dimen0
59 \edef #3{\expandafter\c@lean\the\dimen2}}
60 \newcommand\@ADL@@realmult[3]{\dimen0=#1pt \dimen2=#2\dimen0
61 \xdef #3{\expandafter\c@lean\the\dimen2}}
62 {\catcode`\p=12 \catcode`\t=12\gdef\c@lean #1pt{#1}}

Manual setting of the paper size.

63

64 \@settopoint\paperwidth\@settopoint\paperheight
65 \xdef\@ADL@paperwidth{\expandafter\c@lean\the\paperwidth}
66 \xdef\@ADL@paperheight{\expandafter\c@lean\the\paperheight}
67 \newcommand\setpaperwidth[1]{\setlength\paperwidth{#1}
68 \@settopoint\paperwidth
69 \xdef\@ADL@paperwidth{\expandafter\c@lean\the\paperwidth}}
70 \newcommand\setpaperheight[1]{\setlength\paperheight{#1}
71 \@settopoint\paperheight
72 \xdef\@ADL@paperheight{\expandafter\c@lean\the\paperheight}}
73 \newcommand\@ADL@setdims{%
74 \@ADL@realdiv{\@ADL@paperwidth}{\the\@ADL@columns}\@ADL@boxwidth
75 \@ADL@realdiv{\@ADL@paperheight}{\the\@ADL@rows}\@ADL@boxheight}

Commands for placing the label text and defining the label text.

76

77 \def\offset(#1,#2){\@ADL@realmult{#1}{\@ADL@boxwidth}\@ADL@xoffset
78 \@ADL@realmult{#2}{\@ADL@boxheight}\@ADL@yoffset\let\offset\@ADL@offset}

 79 \def\@ADL@offset(#1,#2){%
 80 \@bsphack\@ADL@@realmult{#1}{\@ADL@boxwidth}\@ADL@xoffsett
 81 \@ADL@@realmult{#2}{\@ADL@boxheight}\@ADL@yoffsett\@esphack}
 82 \newcommand\labeltext[1]{\savebox{\@ADL@labelbox}(0,0)
 83 {\shortstack[\@ADL@ljust]{#1}}\@ADL@filefalse}

Here’s the beef: the row and column loops.

84

 85 \newcommand\rowloop{
 86 \@ADL@numrow\z@
 87 \@ADL@numfile\z@
 88 \loop
 89 \advance\@ADL@numrow by \@ne
 90 {\columnloop}
 91 \ifnum\@ADL@numrow<\@ADL@rows
 92 \@ADL@realadd{\@ADL@ypos}{-\@ADL@boxheight}\@ADL@ypos
 93 \repeat

94 }

95

 96 \newcommand\columnloop{
 97 \@ADL@numcolumn\z@
 98 \@ADL@realmult{\@ADL@xpos}{0}\@ADL@xpos
 99 \loop
100 \advance\@ADL@numcolumn by\@ne
101 \global\advance\@ADL@numfile by\@ne
102 \@ADL@labelfile{text\the\@ADL@numfile}
103 \if@ADL@frames
104  \@ADL@realadd{\@ADL@ypos}{-\@ADL@boxheight}\@ADL@yout
105  \put(\@ADL@xpos,\@ADL@yout){\framebox(\@ADL@boxwidth,\@ADL@boxheight)}
106 \fi
107 \ifnum\@ADL@numcolumn<\@ADL@columns
108 \@ADL@realadd{\@ADL@xpos}{\@ADL@boxwidth}\@ADL@xpos
109 \repeat

110 }

Macros for reading label information from a file.

111

112 \newif\if@ADL@fileread
113 \newsavebox{\@ADL@labelbox}
114 \newcommand\@ADL@labelfile[1]{\@ADL@realadd{0}{\@ADL@xoffset}\@ADL@xoffsett%
115 \@ADL@realadd{0}{\@ADL@yoffset}\@ADL@yoffsett\if@ADL@file\begingroup%
116 \savebox{\@ADL@labelbox}(0,0){\shortstack[\@ADL@ljust]{\@ADL@read{#1}}}%
117 \@ADL@realadd{\@ADL@xpos}{\@ADL@xoffsett}\@ADL@xout%
118 \@ADL@realadd{\@ADL@ypos}{-\@ADL@yoffsett}\@ADL@yout%
119 \put(\@ADL@xout,\@ADL@yout){\usebox{\@ADL@labelbox}}%
120 \if@ADL@fileread{\@ADL@do@everylabel}\fi\endgroup\else%
121 \@ADL@realadd{\@ADL@xpos}{\@ADL@xoffsett}\@ADL@xout%
122 \@ADL@realadd{\@ADL@ypos}{-\@ADL@yoffsett}\@ADL@yout%
123 \put(\@ADL@xout,\@ADL@yout){\usebox{\@ADL@labelbox}}{\@ADL@do@everylabel}\fi}
124 \newcommand\@ADL@read[1]{\openin1#1
125 \ifeof1\relax\global\@ADL@filereadfalse\else\closein1

126 \relax\@@input#1\global\@ADL@filereadtrue\fi}

The command to build the labels.

127

128 \newcommand\makelabels{%
129 \begin{picture}(\@ADL@paperwidth,\@ADL@paperheight)(0,0)
130 \rowloop\end{picture}}

Command for making text that goes on every label.

131

132 \newcount\@ADL@everycount\@ADL@everycount\z@
133 \newcount\@ADL@everylooper
134 \newcommand\everylabel[1]{\global\advance\@ADL@everycount by\@ne%
135 \@namedef{@ADL@everylabel\@roman{\@ADL@everycount}}{#1}}
136 \newcommand\@ADL@do@everylabel{\ifnum\@ADL@everycount>\z@%
137 \@ADL@everylooper\z@
138 \loop
139  \advance\@ADL@everylooper by\@ne
140  \@nameuse{@ADL@everylabel\@roman{\@ADL@everylooper}}
141  \ifnum\@ADL@everylooper<\@ADL@everycount
142 \repeat
143 \fi}

Manual text placement.

144

145 \def\placetext(#1,#2)#3{\@ADL@realmult{#1}{\@ADL@boxwidth}\@ADL@xtextoffset
146 \@ADL@realmult{#2}{\@ADL@boxheight}\@ADL@ytextoffset
147 \@ADL@realadd{\@ADL@xtextoffset}{\@ADL@xpos}\@ADL@xtextout
148 \@ADL@realadd{-\@ADL@ytextoffset}{\@ADL@ypos}\@ADL@ytextout
149 \put(\@ADL@xtextout,\@ADL@ytextout){\makebox(0,0)[\@ADL@tjust]{#3}}}

Set initial “cursor” position and perform other initialisations.

150

151 \@ADL@realadd{\@ADL@paperheight}{0}\@ADL@ypos
152 \def\@ADL@xpos{0}
153 \unitlength 1pt
154 \newcommand\@ADL@ljust{l}
155 \newcommand\@ADL@tjust{l}
156 \ps@empty

157

158 ⟨/labels⟩