summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/misc/card-set.sty
blob: b25f713ff16abf7cba075434cbac6d9d5ed53b1e (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
% card.sty by R. Potu\v cek jr.                                  March 6, 1992 %
%                                                                              %
\message{Card style Version 2.04, March 6, 1992 by R. Potu\v cek jr.}          %
%                                                                              %
% This style allows you to print text formatted for cardfile cards. As it      %
% is a problem to print on such cards anyway, the text ist formatted into      %
% groups of consecutive boxes, so as to allow cutting it out and glueing       %
% together to cardfiles.                                                       %
%                                                                              %
% Card size can be manipulated at will and card pages will be enumerated       %
% optionally and independently for each card, so as to allow texts longer      %
% than one card.                                                               %
%                                                                              %
% The style should work with plain \TeX\ as well es with \LaTeX.               %
%                                                                              %
%                                                                              %
%                                                                              %
%                                                                              %
% If you have any suggestions, questions or comments, please e-mail (with a    %
% Version number please) to:                                                   %
%                                                                              %
%   potucek@winx06.informatik.uni-wuerzburg.de                                 %
%                                                                              %
% ---------------------------------------------------------------------------- %
%                                                                              %
% For use with \LaTeX\ use the environment `card', which expects a parameter   %
% containing material supposed to be set in the header:                        %
%                                                                              %
% \begin{card}{heading}                                                        %
%   ...                                                                        %
% \end{card}                                                                   %
%                                                                              %
% For use with plain \TeX\ÿenclose the actual text between `\card' and         %
% `\endcard':                                                                  %
%                                                                              %
% \card{heading}                                                               %
%   ...                                                                        %
% \endcard                                                                     %
%                                                                              %
% ---------------------------------------------------------------------------- %
%                                                                              %
% The text within the environment will be formatted as follows:                %
%                                                                              %
%    +---------------------------+---------------------------+                 %
%    | heading              page | heading              page |                 %
%    +---------------------------+---------------------------+                 %
%    | Text, broken into small   | allow usage of all other  |                 %
%    | pages of their own, so as | \LateX\ commands.         |                 %
%    | to allow comfortable usage|                           |                 %
%    | as an environment, an to  |                           |                 %
%    +---------------------------+---------------------------+                 %
%                                                                              %
% ---------------------------------------------------------------------------- %
%                                                                              %
% The size of the card is set by \cardheight and \cardwidth. The distance of   %
% the text from the borders is set by \cardfreespace. Pagenubers can be        %
% selected by setting:                                                         %
%                                                                              %
%   \let\cardpageno\on          % turn on pagenumbers                          %
%   \let\cardpageno\off         % turn off pagenumbers                         %
%                                                                              %
% Before each card and between two boxes \cardfreespace will be inserted.      %
% Furthermore there is a token register called `\everycard' that is executed   %
% at the beginning of every card, so as to allow a general style definition    %
% for every card, which then may be dependent on the environment you use.      %
%                                                                              %
% If you don't like empty pages to be printed, i.e. pages that have a header   %
% but don't contain any text, you can suppress printing by setting:            %
%                                                                              %
%   \let\cardprtempty\off       % suppress empty pages                         %
%   \let\cardprtempty\on        % print emty pages                             %
%                                                                              %
% ---------------------------------------------------------------------------- %
%                                                                              %
% These are the parameters you may change, however you should modify them in   %
% your source file rather than changing these global presets!                  %
%                                                                              %
\edef\on{1 }\edef\off{0 }

\let\cardpageno\on
\let\cardprtempty\on

\newdimen\cardwidth        \cardwidth74mm
\newdimen\cardheight       \cardheight52mm
\newdimen\cardfreespace    \cardfreespace5pt
\newdimen\cardsepamount    \cardsepamount\medskipamount

\newtoks\everycard          \everycard{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Don't change anything that follows! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Allow `@' in command names;
%
\ifcat @a \def\card@atdef{1} \else \catcode`\@=11 \def\card@atdef{0} \fi

% Declare registers needed:
%
\newdimen\card@height       \card@height\cardheight
\newdimen\card@headheight   \card@headheight12pt
\newdimen\card@tmpdim
\newdimen\card@ghsize
\newdimen\card@gvsize

\newbox\card@textboxone
\newbox\card@textboxtwo
\newbox\card@pagebox
\newbox\card@strutbox

\newtoks\origout
\newtoks\card@lhead         \card@lhead={}
\newtoks\card@rhead         \card@rhead={}

\newcount\card@pagecount    \card@pagecount0
\newcount\card@lcount       \card@lcount1
\newcount\card@rcount       \card@rcount2
\newcount\card@lrf          \card@lrf0

\def\on{1}
\def\off{0}
% Message macro for debugging:
%
\def\card@db#1#2{
    \ifnum#1<0  \message{#2} \fi
}

% Define strut for cardhead. Default is \strut. It shouldn't be needed but
% let's make sure:
%
\def\card@strut{\strut}
\def\card@makestrut#1{
    \global\def\card@strut{\copy\card@strutbox}
    \global\setbox\card@strutbox=\hbox{\vphantom{#1}}
    \card@tmpdim=\ht\card@strutbox \advance\card@tmpdim 1.4pt\global\ht\card@strutbox=\card@tmpdim
    \card@tmpdim=\dp\card@strutbox \advance\card@tmpdim 1.4pt\global\dp\card@strutbox=\card@tmpdim
}

% Flush contents of \TeX's vertical list:
%
\def\card@preflush{
    \origout=\output
    \card@tmpdim\vsize \vsize2\vsize
    \global\setbox\card@pagebox=\vbox{}
    \output={
        \card@db1{:}
        \global\setbox\card@pagebox=\vbox{
            \unvbox\card@pagebox
            \par\noindent\vskip\cardsepamount
            \ifvbox255\unvbox255
            \else\box255\fi
        }
    }
    \par\penalty-\@M
    \output=\origout
    \vsize\card@tmpdim
    \ifvbox\card@pagebox \else
        \global\setbox\card@pagebox=\vbox{\box\card@pagebox}
    \fi
}

% Initialize all local parameters of a card with those infos available.
% Furthermore change \output temporarily to allow page breaking within a card.
%
\def\card@init#1{
    \card@preflush
    \origout=\output
    \output={\card@output}
    \card@ghsize\hsize
    \card@gvsize\vsize
    \card@makestrut{#1}
    \card@lhead={#1\ifnum\on=\cardpageno\hfill\the\card@lcount\hskip\cardfreespace\else\fi}
    \card@rhead={#1\ifnum\on=\cardpageno\hfill\the\card@rcount\hskip\cardfreespace\else\fi}
    \global\card@headheight0pt
        \global\advance\card@headheight \ht\card@strutbox
        \global\advance\card@headheight \dp\card@strutbox
    \global\card@tmpdim\cardheight
        \global\advance\card@tmpdim -\card@headheight
        \global\card@height\card@tmpdim
        \global\advance\card@tmpdim -2\cardfreespace
               \vsize\card@tmpdim
    \global\card@tmpdim\cardwidth
        \global\advance\card@tmpdim -2\cardfreespace
               \hsize\card@tmpdim
    \global\card@pagecount0
    \global\card@lcount1
    \global\card@rcount2
    \global\card@lrf0
    \topskip0pt
    \card@db0{(}
}

% Restore \hsize, \vsize and \output to previous values:
%
\def\card@exit{
    \global\advance\card@lrf 2
    \the\output
    \hsize\card@ghsize %globa?
    \vsize\card@gvsize
    \output=\origout
    \origout={}
    \card@db0{)}
}

% Make cardfile-card with global dimensions and {lhead}{rhead}{lbody}{rbody}
%
\def\makecard#1#2#3#4{
    \vbox to \cardheight{
        \hrule
        \hbox to 2\cardwidth{\vrule
            \hbox to \cardwidth{\card@strut\hskip\cardfreespace#1\hss}\hss\vrule
            \hbox to \cardwidth{\card@strut\hskip\cardfreespace#2\hss}\hss\vrule}
        \hrule
        \hbox to 2\cardwidth{\vrule\hbox to \cardwidth{\hskip\cardfreespace
            \vbox to \card@height{\vskip\cardfreespace#3\vss}\hss
            \hss}\hss\vrule\hbox to \cardwidth{\hskip\cardfreespace
            \vbox to \card@height{\vskip\cardfreespace#4\vss}\hss
            \hss}\hss\vrule}
        \vss
        \hrule
    }
}

% Test whether left box contains any material
%
\newif\ifcard@page
\def\ifpage{
    \ifnum\the\card@lrf>0 \card@pagetrue        % Create output
    \else                 \card@pagefalse \fi   % unless regular left
    \ifnum\the\card@lrf=2
        \ifvbox\card@textboxone\else            % or empty
            \card@pagefalse
        \fi
        \ifnum\cardprtempty=\on\relax
            \ifnum\the\card@lcount=1
                \card@pagetrue
            \fi
        \fi
    \fi
    \ifcard@page
}

% Actual \output routine. This routine does not create any output. Rather it
% writes such boxes as it wishes to output into \card@pagebox, which then is
% passed to the regular output routine!
%
\def\card@output{
    \global\advance\card@pagecount 1
    \ifcase\the\card@lrf
            \global\setbox\card@textboxone=\box255\global\card@lcount\card@pagecount \card@db0{ (0,<\the\card@pagecount>) }
        \or \global\setbox\card@textboxtwo=\box255\global\card@rcount\card@pagecount \card@db0{ (1,<\the\card@pagecount>) }
        \or \global\setbox\card@textboxone=\box255\global\card@lcount\card@pagecount \card@db0{ (2,<\the\card@pagecount>) }
        \or \global\setbox\card@textboxtwo=\box255\global\card@rcount\card@pagecount \card@db0{ (3,<\the\card@pagecount>) }
    \fi
    \ifpage
        \global\setbox\card@pagebox=\vbox{\unvbox\card@pagebox
            \par\noindent\vskip\cardsepamount
            \makecard{\the\card@lhead}{\the\card@rhead}
                     {\box\card@textboxone}{\box\card@textboxtwo}
        }
    \fi
%   Test routines:
%   \ifnum\the\card@lrf>1 \shipout\box\card@pagebox \fi % for testing only
%   \ifnum\the\card@lrf>1 \shipout\copy\card@pagebox \fi % for testing only
    \ifnum\the\card@lrf>0 \global\card@lrf0 \else \global\card@lrf1 \fi
}

% The actual definition of the environment comes here, so as to allow use
% with plain \TeX\ as well:
%
\long\def\card#1{
    \begingroup
    \card@db2{#1}
    \card@init{#1}
    \the\everycard
    \par
}
\long\def\endcard{
    \vfill
    \penalty-\@M
    \card@exit
    \unvbox\card@pagebox
    \endgroup
}

% Restore `@' to catcode `other' if needed:
%
\ifx0\card@atdef \catcode`@=12 \else \fi