Debian Codegraph @

texmf-dist/tex/generic/midnight/border.tex

raw
1 \ifx\BORDER\relax\endinput\else\let\BORDER=\relax\fi % \input only once
2 %
3 % border.tex: Macros to typeset borders.
4 % version: 1.0 release: 21 October 1991
5 %
6 % copyright (c) 1991 Marcel R. van der Goot
7 % You can use these macros to typeset documents. You may
8 % distribute this file freely, provided that you also distribute
9 % the accompanying documentation.
10 % You may make changes to this file, or extract portions
11 % of it for inclusion in other files, provided that
12 % (1) you change the name of the file;
13 % (2) you give proper credit and include copyright
14 % information where applicable;
15 % (3) explain how an unchanged version can be obtained; and
16 % (4) document the usage of your macros/changes (if usage
17 % of your macros is not worth documenting, they must not
18 % be worth using).
19 % You are not allowed to use the name ``Midnight Macros'' for
20 % any changed files.
21 % The above rules for making changes do not apply where it
22 % is explicitly noted in this file that something can be changed
23 % to conform to your local installation.
24 %
25 % USAGE:
26 % See the file border.doc
27 %
28 % original: csvax.cs.caltech.edu [131.215.131.131] in pub/tex
29 % (use anonymous ftp). Also in various archives.
30 %
31 % Caltech, Pasadena --- Marcel van der Goot
32 % [email protected]
33 % Caltech 256--80
34 % Pasadena, CA 91125
35 % USA
36 % (818) 356--4603
37 %
38
39 % update history:
40 % version 1.0: This one.
41 % release 21 Oct 1991: The original
42 %
43
44 %%%%%% CODE: (you don't need to read this to use the macros)
45
46 \edef\borderelm{\the\catcode`\_} % minor trick to remember the catcode
47 \catcode`\_=11% letter, to make private macros
48
49 % Note: we use \box0, \box2, \box4, \dimen0, \dimen2, and \count2, rather than
50 % allocating new boxes, dimensions, and counts. That is usually ok because all
51 % assignments are done within \hbox{...} or \vbox{...}, which provides
52 % grouping.
53
54 %%%%%%% exactly fitting border with overlaps
55 % \border makes a border of the specified dimensions, by overlapping some
56 % of the elements when necessary.
57 % \hborder takes four arguments, the width, and the indices of the left
58 % element, the middle element, and the right element. It makes an horizontal
59 % border of the form \hbox to wd{ l m+ r }, where there is at least one m.
60 % If wd is large enough to set at least {l m r}, all overlap is between
61 % elements of type m. In the unusual case where wd is too small, the overlap
62 % is necessarily with the corner elements.
63
64 \def\hborder#1#2#3#4% wd, l, m, r
65 {\hbox to#1
66 {\setbox0=\hbox{\borderelm#3}%
67 \borderelm#2%
68 \hskip0pt minus1fil %
69 \copy0\kern-.5\wd0 %
70 \cleaders\copy0\hskip0pt plus1fil %
71 \kern-.5\wd0\copy0 %
72 \hskip0pt minus1fil %
73 \borderelm#4%
74 }%
75 }
76
77 % \border does the vertical equivalent of \hborder: the top and bottom
78 % elements are hboxes generated with \hborder, and the middle element is
79 % an \hbox{ l \hss r }. This middle element is again used at least once,
80 % and if possible all overlap will be among middle elements.
81 % The \kern0sp at the end is to get depth 0, rather than the depth of
82 % the last hbox. (\boxmaxdepth is set to the largest possible value to make
83 % sure that the depth is indeed 0, not negative.)
84
85 \def\border#1#2% ht, wd
86 {\vbox to#1
87 {\offinterlineskip\boxmaxdepth=\maxdimen
88 \dimen2=#2
89 \setbox0=\hbox to\dimen2{\borderelm3\hss\borderelm4}
90 \dimen0=\ht0 \advance\dimen0 by\dp0
91 \hborder{\dimen2}012
92 \vskip0pt minus1fil
93 \copy0\kern-.5\dimen0
94 \cleaders\copy0\vskip0pt plus1fil
95 \kern-.5\dimen0\copy0
96 \vskip0pt minus1fil
97 \hborder{\dimen2}567
98 \kern0sp
99 }%
100 }
101
102 %%%%%%% exactly fitting border with spaces
103 % \xborder also makes a border of the specified dimensions, but rather than
104 % overlapping elements, it leaves space between the elements.
105 % \xhborder makes a horizontal border. Unlike \hborder, there are zero (not
106 % one) or more middle elements. The extra space is equally distributed
107 % between all the elements.
108
109 \def\hxborder#1#2#3#4% wd, l, m, r
110 {\hbox to#1
111 {\setbox0=\hbox{\borderelm#3}%
112 \borderelm#2%
113 \xleaders\copy0\hskip0pt plus1fil minus1fil %
114 \borderelm#4%
115 }%
116 }
117
118 % \xborder is to \hxborder as \border is to \hborder.
119
120 \def\xborder#1#2% ht, wd
121 {\vbox to#1
122 {\offinterlineskip\boxmaxdepth=\maxdimen
123 \dimen2=#2
124 \setbox0=\hbox to\dimen2{\borderelm3\hss\borderelm4}
125 \hxborder{\diemn2}012
126 \xleaders\copy0\vskip0pt plus1fil minus1fil
127 \hxborder{\dimen2}567
128 \kern0sp
129 }%
130 }
131
132 %%%%%%% rounded border with abutting elements
133 % \plusborder and \minusborder make borders with abutted elements (no
134 % overlaps, no spaces). To make this possible, the border dimensions are
135 % rounded so that an integral number of elements fits. \plusborder rounds
136 % up, \minusborder rounds down. \plusgray and \minusgray are similiar, except
137 % that \borderelm8 is used as center element (normally the center is white).
138 % \plus_border and \minus_border are used for both, where the 3rd argument
139 % indicates whether there is a center element.
140
141 % The computation consists of determining the space D that has to be
142 % filled with middle elements. If the width of the middle element is d,
143 % there fit (D div d) middle element in a `minus border.'
144 % To avoid minor inaccuracies in the arithmetic, what we actually do is
145 % (D+100sp) div d. 100sp is so small as to be invisible.
146
147 \def\hminusborder#1#2#3#4% wd, l, m, r
148 {\hbox
149 {\dimen0=#1\count2=\dimen0 %
150 \setbox0=\hbox{\borderelm#2}\advance\count2 by-\wd0 %
151 \setbox0=\hbox{\borderelm#4}\advance\count2 by-\wd0 %
152 \setbox0=\hbox{\borderelm#3}%
153 \advance\count2 by100 %
154 \divide\count2 by\wd0 %
155 \borderelm#2%
156 \cleaders\copy0\hskip\count2\wd0 %
157 \borderelm#4%
158 }%
159 }
160
161 \def\minus_border#1#2#3% ht, wd, #3=empty ==> no center element
162 {\vbox
163 {\offinterlineskip\boxmaxdepth=\maxdimen
164 \dimen2=#2\relax
165 \dimen0=#1\count2=\dimen0
166 \setbox0=\hminusborder{\dimen2}012
167 \advance\count2 by-\ht0 \advance\count2 by-\dp0
168 \setbox2=\hminusborder{\dimen2}567
169 \advance\count2 by-\ht2 \advance\count2 by-\dp2
170 \if.#3.\setbox4=\hbox to\wd0{\borderelm3\hss\borderelm4}
171 \else \setbox4=\hminusborder{\dimen2}384
172 \fi
173 \advance\count2 by100
174 \dimen0=\ht4\advance\dimen0 by\dp4
175 \divide\count2 by\dimen0
176 \box0
177 \cleaders\copy4\vskip\count2\dimen0
178 \box2
179 \kern0sp
180 }%
181 }
182
183 \def\minusborder#1#2{\minus_border{#1}{#2}{}}
184
185 \def\minusgray#1#2{\minus_border{#1}{#2}{1}}
186
187
188 % Rounding upwards is achieved with (D + d - 1) div d, but again, we
189 % actually do (D + d - 100sp) div d.
190
191 \def\hplusborder#1#2#3#4% wd, l, m, r
192 {\hbox
193 {\dimen0=#1\count2=\dimen0 %
194 \setbox0=\hbox{\borderelm#2}\advance\count2 by-\wd0 %
195 \setbox0=\hbox{\borderelm#4}\advance\count2 by-\wd0 %
196 \setbox0=\hbox{\borderelm#3}%
197 \advance\count2 by\wd0\advance\count2 by-100 %
198 \divide\count2 by\wd0 %
199 \borderelm#2%
200 \cleaders\copy0\hskip\count2\wd0 %
201 \borderelm#4%
202 }%
203 }
204
205 \def\plus_border#1#2#3% ht, wd, #3=empty ==> no center element
206 {\vbox
207 {\offinterlineskip\boxmaxdepth=\maxdimen
208 \dimen2=#2\relax
209 \dimen0=#1\relax\count2=\dimen0
210 \setbox0=\hplusborder{\dimen2}012
211 \advance\count2 by-\ht0 \advance\count2 by-\dp0
212 \setbox2=\hplusborder{\dimen2}567
213 \advance\count2 by-\ht2 \advance\count2 by-\dp2
214 \if.#3.\setbox4=\hbox to\wd0{\borderelm3\hss\borderelm4}
215 \else\setbox4=\hplusborder{\dimen2}384
216 \fi
217 \dimen0=\ht4\advance\dimen0 by\dp4
218 \advance\count2 by\dimen0\advance\count2 by-100
219 \divide\count2 by\dimen0
220 \box0
221 \cleaders\copy4\vskip\count2\dimen0
222 \box2
223 \kern0sp
224 }%
225 }
226
227 \def\plusborder#1#2{\plus_border{#1}{#2}{}}
228
229 \def\plusgray#1#2{\plus_border{#1}{#2}{1}}
230
231 %%%%%%% border example (rounded corners)
232 % This example creates a border with rounded corners. The corners are taken
233 % from the manfnt font, as described in The TeXbook, p.389. However, we
234 % reposition them in their boxes, as their original position is inconvenient:
235 % We want tight-fitting boxes, because the boxes determine the border width
236 % and height. The original position is described in The TeXbook.
237
238 % If \manfnt is already defined, we do not redefine it.
239 \ifx\manfnt\UNDEFINED
240 \font\manfnt=manfnt
241 \fi
242
243 % \roundcorners is a bit messy, but that is not so important.
244 % Just so that you can use \minusgray and \plusgray, we added a center
245 % character (just some random character from the font). That meant that the
246 % left and right character had to be given widths equal to the corner elements.
247 % \roundcorners scales properly with \manfnt.
248
249 \def\roundcorners#1% use as \borderelm
250 {{\manfnt
251 \setbox2=\hbox{\char'44}% for demonstration purposes
252 \ifcase#1
253 \setbox0=\hbox{d}% lu
254 \hbox to\ht0{\vbox to\fontdimen8\font{\vss\box0}\hss}%
255 \or\hbox{\vrule width\wd2 height\fontdimen8\font depth0pt\hss}% u=d
256 \or\setbox0=\hbox{a}% ru
257 \hbox to\ht0{\kern\dp0\vbox to\fontdimen8\font{\vss\box0}\hss}%
258 \or\setbox0=\hbox{d}%
259 \hbox to\ht0{\vrule width\fontdimen8\font height\ht2 depth\dp2\hss}% l
260 \or\setbox0=\hbox{d}%
261 \hbox to\ht0{\hss\vrule width\fontdimen8\font height\ht2 depth\dp2}% r
262 \or\setbox0=\hbox{c}% ld
263 \hbox to\ht0{\vbox{\copy0\kern-\dp0}\hss}%
264 \or\hbox{\vrule width\wd2 height\fontdimen8\font depth0pt\hss}% d=u
265 \or\setbox0=\hbox{b}% rd
266 \hbox to\ht0{\kern\dp0\vbox{\copy0\kern-\dp0}\hss}%
267 \or\box2 % center character
268 \fi
269 }}
270
271 %%%%%%% centering text within a border
272 % \setborder[bwd, hspace, vspace]\bordermacro uses \bordermacro (one of
273 % \border, \xborder, etc.) to typeset a border. The width of the border is bwd,
274 % the height of the border depends on the amount of text within the border.
275 % This text is read and typeset in a vbox, with the hsize set so that the
276 % width has the appropriate value. This is done in a somewhat convoluted way
277 % with \afterassignment to set the hsize, and \aftergroup to create the border.
278 % The reason is that now the text is not read as an argument of \setborder,
279 % which is important, for instance, if the text contains catcode changes.
280 % We did not write \setborder[#1,#2,#3]#4#{ , which would have ensured that a
281 % brace follows: that would have required an explicit brace, whereas now you
282 % can also use \bgroup (useful if you want to put \setborder in some other
283 % macro).
284
285 \newbox\brd_txt
286 \newbox\brd_box
287
288 \def\setborder[#1,#2,#3]#4% wd, hspace, vspace, bordermacro
289 {\def\brd_inbox
290 {\hsize=#1
291 \advance\hsize by-#2
292 \advance\hsize by-#2
293 \aftergroup\set_border
294 }%
295 \def\set_border
296 {\setbox\brd_txt=\vbox
297 {\vskip#3
298 \box\brd_txt
299 \vskip#3
300 }%
301 \setbox\brd_box=#4{\ht\brd_txt}{#1}%
302 \vbox to\ht\brd_box
303 {\copy\brd_box \kern-\ht\brd_box
304 \vss
305 \hbox to\wd\brd_box{\hss\box\brd_txt\hss}
306 \vss
307 }%
308 }%
309 \afterassignment\brd_inbox
310 \setbox\brd_txt=\vbox
311 }
312
313
314 %%%%%%% initialization
315
316 \catcode`\_=\borderelm % restore catcode
317
318 \let\borderelm=\roundcorners % only reasonable initialization
319