summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/jlabels/jlabels.sty
blob: fa892aa595e752670045899c4aff0a89a8f74aaf (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
%% This is jlabels.sty written by Jamal K. Tartir.
%%
%% jktartir@hotmail.com
%%
%% A latex package designed to make letter-sized pages of labels.
%%
%% Copyright 2011 by Jamal K. Tartir.
%%
%% All rights reserved.
%%
%% This file may be modified for individual use.
%% 
%% A modified version of this file my not be
%% distributed under its original name.

%% Alternately, this work may be distributed and/or modified
%% under the conditions of the LaTeX Project Public License.

%%%%%     PACKAGES     %%%%%

\RequirePackage{calc}
\RequirePackage{ifthen}
\RequirePackage{pstricks}
\RequirePackage{etoolbox}

%%%%%     NEW LENGTHS     %%%%%

\newlength{\jlabelHorizontalPitch}
\newlength{\jlabelVerticalPitch}

%%%%%     COUNTERS     %%%%%

\newcounter{jlabelxcoordinate}
\newcounter{jlabelycoordinate}
\newcounter{jlabelNumberOfRowsPerPage}
\newcounter{jlabelNumberOfColumnsPerPage}
\newcounter{jlabelNumberOfLabelsPerPage}
\newcounter{jlabelNumberOfLabelsOnThisPage}
\newcounter{jlabelNumberOfTimesThisLabel}

%%%%%     DEFINITIONS     %%%%%

\def\jlabeljustify{l}

\def\jlabelfillstylec{%
\gdef\setjlabelcoordinates{%
\setcounter{jlabelxcoordinate}{%
\value{jlabelNumberOfLabelsOnThisPage}/\value{jlabelNumberOfRowsPerPage}}%
\setcounter{jlabelycoordinate}{%
(\value{jlabelxcoordinate}*\value{jlabelNumberOfRowsPerPage})
-\value{jlabelNumberOfLabelsOnThisPage}}}}

\def\jlabelfillstyler{%
\gdef\setjlabelcoordinates{%
\setcounter{jlabelycoordinate}{%
-\value{jlabelNumberOfLabelsOnThisPage}/\value{jlabelNumberOfColumnsPerPage}}
\setcounter{jlabelxcoordinate}{%
(\value{jlabelycoordinate}*\value{jlabelNumberOfColumnsPerPage})
+\value{jlabelNumberOfLabelsOnThisPage}}}}

%%%%%     COMMANDS     %%%%%

\newcommand{\jlabelLengths}[9][1in]{%
%% #1: Units
%% #2: Left Margin
%% #3: Top Margin
%% #4: Label Width
%% #5: Label Height
%% #6: Number of Rows
%% #7: Number of Columns
%% #8: Horizontal Gap
%% #9: Vertical Gap
%
\setlength{\voffset}{-1in}
\setlength{\hoffset}{-1in}
\setlength{\textwidth}{8in}
\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\headheight}{0pt}
\setlength{\marginparsep}{0pt}
\setlength{\footskip}{0pt}
\setlength{\topmargin}{0pt}
\setlength{\headsep}{0pt}
\setlength{\marginparwidth}{0pt}
\setlength{\marginparpush}{0pt}
%
\setlength{\unitlength}{#1}%
%
\setlength{\jlabelHorizontalPitch}{#4\unitlength}
\setlength{\jlabelVerticalPitch}{#5\unitlength}
%
\addtolength{\hoffset}{#2\unitlength}
\addtolength{\hoffset}{.5\jlabelHorizontalPitch}
\setlength{\textheight}{#3\unitlength}
\addtolength{\textheight}{.5\jlabelVerticalPitch}
\addtolength{\jlabelHorizontalPitch}{#8\unitlength}
\addtolength{\jlabelVerticalPitch}{#9\unitlength}
%
\setcounter{jlabelNumberOfRowsPerPage}{#6}
\setcounter{jlabelNumberOfColumnsPerPage}{#7}
\setcounter{jlabelNumberOfLabelsPerPage}{#6*#7}
%
\psset{xunit=\jlabelHorizontalPitch}
\psset{yunit=\jlabelVerticalPitch}}

\newcommand{\beginjlabels}[1][c]{%
\csexpandonce{jlabelfillstyle#1}%
\xdef\thisjlabelfillstyle{#1}%
\thispagestyle{empty}%

\setcounter{jlabelNumberOfLabelsOnThisPage}{0}

\text{ }

\vfill

\noindent%
\begin{pspicture}(0,0)}

\def\endjlabels{\end{pspicture}}

\newcommand{\jlabelt}[2][1]{%
%
\setcounter{jlabelNumberOfTimesThisLabel}{0}%
\whiledo{\value{jlabelNumberOfTimesThisLabel}<#1}{%
%
\ifthenelse{%
\value{jlabelNumberOfLabelsOnThisPage}<\value{jlabelNumberOfLabelsPerPage}}%
{}{\endjlabels\newpage\beginjlabels[\thisjlabelfillstyle]}%
%
\setjlabelcoordinates%
%
\rput(\value{jlabelxcoordinate},\value{jlabelycoordinate})%
{\begin{tabular}{\jlabeljustify}#2\end{tabular}}%
%
\addtocounter{jlabelNumberOfLabelsOnThisPage}{1}%
%
\addtocounter{jlabelNumberOfTimesThisLabel}{1}}%%      end whiledo
}

\newcommand{\myjlabel}[2]{\csgdef{myjlabeladdress#1}{#2}}

\newcommand{\jlabel}[2][1]{\jlabelt[#1]{\csexpandonce{myjlabeladdress#2}}}