]> mj.ucw.cz Git - ucwmac.git/blob - ucw-labels.tex
Added ucw-labels: simple macros for typesetting of labels (stickers)
[ucwmac.git] / ucw-labels.tex
1 %% Macros for typesetting of labels
2
3 % Default page parameters. You can change them before calling \setuplabels.
4 \setmargins{0pt}
5 \setuppage
6
7 % Do we want rules around each label?
8 \newif\iflabelrules
9 \labelrulesfalse
10
11 % Do we want cropmarks?
12 \newif\iflabelcropmarks
13 \labelcropmarksfalse
14 \def\labelcropm{\iflabelcropmarks\hbox to 0pt{\hss\vbox to \labelh{\crosshair{5pt}\vss\crosshair{5pt}}}\fi}
15
16 % Margins of each label
17 \newdimen\labelhmargin
18 \labelhmargin=5mm
19
20 \newdimen\labelvmargin
21 \labelvmargin=5mm
22
23 % Internals
24 \newdimen\labelw
25 \newdimen\labelh
26 \newcount\labelnum
27
28 % Prepare of typesetting of #2 rows per #1 labels
29 \def\setuplabels#1#2{
30         \labelw=\hsize
31         \divide\labelw by #1
32         \labelh=\vsize
33         \divide\labelh by #2
34         \labelnum=#1
35         \multiply\labelnum by #2
36         \offinterlineskip
37         \parindent=0pt
38         \parskip=0pt
39         \rightskip=0pt plus 0.1pt
40 }
41
42 % Typeset one label as a box (in most cases, you want to use \label instead)
43 \long\def\labelbox#1{\hbox to \labelw{%
44   \labelcropm
45   \iflabelrules\vrule\fi
46   \hss
47   \vbox to \labelh{%
48     \iflabelrules\hrule\fi
49     \vss
50     \hbox to \labelw{%
51       \hss
52       \vbox to \labelh{%
53         \vss
54         \dimen0=\labelh
55         \advance\dimen0 by -2\labelvmargin
56         \vbox to \dimen0{%
57           \hsize=\labelw
58           \advance\hsize by -2\labelhmargin
59           \normalbaselines
60           #1
61         }%
62         \vss
63       }%
64       \hss
65     }
66     \vss
67     \iflabelrules\hrule\fi
68   }%
69   \hss
70   \labelcropm
71   \iflabelrules\vrule\fi
72   }%
73 }
74
75 % Typeset one label (#1 is expected to have the exact height, so it usually ends with a \vfil)
76 \long\def\label#1{\leavevmode\labelbox{#1}\penalty -100}
77
78 % Typeset #1 copies of label #2
79 \newcount\labelcount
80 \long\def\labels#1#2{{\leavevmode\setbox0=\labelbox{#2}%
81   \labelcount=#1%
82   \loop
83     \copy0
84     \penalty -100
85     \advance\labelcount by -1
86   \ifnum\labelcount>0\repeat
87 }}
88
89 % Fill the whole page with copies of a label
90 \long\def\labelfill#1{\labels\labelnum{#1}}