Debian Codegraph @

texmf-dist/source/latex/niceframe/niceframe.dtx

raw
1 % \iffalse meta-comment
2 %
3 % This package is distributed in the hope that it will be useful,
4 % but WITHOUT ANY WARRANTY; without even the implied warranty of
5 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
6 %
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 % http://www.latex-project.org/lppl.txt
12 % and version 1.3 or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later.
14 %
15 % This work has the LPPL maintenance status `maintained'.
16 %
17 % The Current Maintainer of this work is Marcus Ohlhaut.
18 %
19 % This work consists of the files niceframe.dtx and niceframe.ins
20 % and the derived file niceframe.sty.
21 %
22 % Copyright (C) 2009 Marcus Ohlhaut ([email protected]).
23 % All rights reserved.
24 %
25 % \fi
26 %% \CharacterTable
27 %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
28 %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
29 %% Digits \0\1\2\3\4\5\6\7\8\9
30 %% Exclamation \! Double quote \" Hash (number) \#
31 %% Dollar \$ Percent \% Ampersand \&
32 %% Acute accent \' Left paren \( Right paren \)
33 %% Asterisk \* Plus \+ Comma \,
34 %% Minus \- Point \. Solidus \/
35 %% Colon \: Semicolon \; Less than \<
36 %% Equals \= Greater than \> Question mark \?
37 %% Commercial at \@ Left bracket \[ Backslash \\
38 %% Right bracket \] Circumflex \^ Underscore \_
39 %% Grave accent \` Left brace \{ Vertical bar \|
40 %% Right brace \} Tilde \~}
41 %%
42 \def\fileversion{1.1c}
43 \def\filedate{2009/31/08}
44 %
45 % \CheckSum{282}
46 %
47 %\iffalse
48 %
49 % Package NiceFrame to be used with LaTeX 2e
50 % Copyright (C) 1996-2009 Marcus Ohlhaut ([email protected]).
51 % All rights reserved.
52 %
53 % Error reports for UNCHANGED versions please to:
54 % [email protected]
55 %
56 %\fi
57 %
58 % \title{A style option to create nice frames with the \textbf{dingbat}
59 % fonts\thanks{This file has version number \fileversion\ --
60 % last revision \filedate.}}
61 %
62 % \author{Marcus Ohlhaut\\
63 % Wertheimer Stra\ss e 59\\
64 % D-81243 M\"unchen\\
65 % {\tt [email protected]}}
66 %
67 % \date{Printed \today}
68 % \maketitle
69 %
70 % \changes{1.0}{1995/07/08}{Adapted this to LaTeX2e}
71 % \changes{1.0a}{1995/07/13}{Added CurlyFrame and ArtDecoFrame}
72 % \changes{1.0b}{1995/07/16}{Fixed documentation}
73 % \changes{1.0c}{1996/02/11}{Fixed 8+3 names}
74 % \changes{1.1}{1996/02/20}{Redesign of GeneralFrame}
75 % \changes{1.1b}{1996/10/20}{Fixed alignment of right vleaders}
76 % \changes{1.1b}{1996/10/20}{Changed command names to lowercase}
77 % \changes{1.1b}{1996/10/20}{Adapted installation to new version of docstrip}
78 % \changes{1.1c}{2009/08/31}{Changed license to LPPL 1.3}
79 %
80 % \DoNotIndex{\addtolength,\baselineskip,\begin,\bigskip,\box}
81 % \DoNotIndex{\centerline,\char,\CodelineIndex,\columnsep,\columnwidth}
82 % \DoNotIndex{\DocInput,\documentclass,\dots,\dp}
83 % \DoNotIndex{\EnableCrossrefs,\end}
84 % \DoNotIndex{\font,\hbox,\headsep,\hfill,\hsize,\hss,\ht}
85 % \DoNotIndex{\LARGE,\Large,\leaders,\MakeShortVerb,\marginparwidth}
86 % \DoNotIndex{\NeedsTeXFormat,\newcommand,\newlength,\oddsidemargin}
87 % \DoNotIndex{\pagestyle,\parindent,\parskip,\pixel,\ProvidesPackage,\pxl}
88 % \DoNotIndex{\RecordChanges,\setbox,\setlength,\settowidth}
89 % \DoNotIndex{\textheight,\textwidth,\thin,\topmargin,\typeout}
90 % \DoNotIndex{\usepackage,\vbox,\vfill,\vsize,\vskip,\vss}
91 % \DoNotIndex{\wd,\\,\|\ }
92 %
93 % \begin{abstract}
94 % This article describes a new style option that can be used with the
95 % document styles that are distributed with the \LaTeX\ distributions.
96 % It defines new commands to frame material with decorative frames,
97 % using \textbf{dingbat} fonts.
98 % \end{abstract}
99 %
100 % \tableofcontents
101 %
102 % \section{Introduction}
103 %
104 % When I set out to become familar with all the fonts available for
105 % \TeX, I came across the \textbf{dingbat} font. Only a few glyphs have
106 % been defined in that font, and some of them are intended to yield
107 % nice frames when set appropriately.
108 %
109 % I didn't want to work out the details of arranging the glyphs each
110 % time I needed to frame text, and hence wrote this little package to
111 % do the work for me.
112 %
113 % When testing this, I noticed that one of the glyphs was wrongly coded
114 % in the original \textbf{dingbat} distribution. Together with this
115 % package, a corrected version of \textbf{dingbat} is distributed.
116 %
117 % This package has no options. It requires the package |calc| by Kresten~K.
118 % Thorup and Frank Jensen.
119 %
120 % \section{The user interface}
121 % This package defines three commands, |\niceframe|, |\curlyframe| and
122 % |\artdecoframe|. All three take one mandatory and one optional argument.
123 % The mandatory argument specifies the material that is to be framed
124 % (anything which can go into a |\vbox|), whereas the optional argument
125 % specifies the final width of the frame.
126 %
127 % If the optional argument is omitted, the frame will be exactly of
128 % width |\textwidth|. The height of the frame is calculated from the
129 % natural height of the enclosed material.
130 %
131 % These frames have to be set into their own paragraphs, otherwise the
132 % width of the surrounding text will not be correct.
133 %
134 % The package also defines a more general macro called |\generalframe|
135 % to allow control over the symbols which are used to build the frame.
136 %
137 % \section{The implementation}
138 % \subsection{The {\sc docstrip} modules}
139 %
140 % The following modules are used in the implementation to direct
141 % {\sc docstrip} in generating the external files:
142 % \begin{center}
143 % \begin{tabular}{ll}
144 % driver & produce the documentation driver file \\
145 % package & produce the package file \\
146 % example & produce an example file \\
147 % \end{tabular}
148 % \end{center}
149 %
150 % \subsection{Producing the documentation}
151 %
152 % A short driver is provided that can be extracted (if necessary)
153 % by the {\sc docstrip} program provided with \LaTeXe.
154 % \begin{macrocode}
155 %<*driver>
156 \documentclass{ltxdoc}
157
158 % dimensions from ltugboat.sty:
159 \setlength\textwidth{31pc} \setlength\textheight{54pc}
160 \setlength{\parindent}{0pt}
161 \setlength{\parskip}{2pt plus 1pt minus 1pt}
162 \setlength{\oddsidemargin}{8pc}
163 \setlength{\marginparwidth}{8pc}
164 \setlength{\topmargin}{-2.5pc}
165 \setlength{\headsep}{20pt}
166 \setlength{\columnsep}{1.5pc}
167 \setlength{\columnwidth}{18.75pc}
168 \EnableCrossrefs
169 \RecordChanges
170 \CodelineIndex
171
172 \MakeShortVerb{\|}
173 \begin{document}
174
175 \DocInput{niceframe.dtx}
176
177 \end{document}
178 %</driver>
179 % \end{macrocode}
180 %
181 % \subsection{The example}
182 %
183 % This is just a short \LaTeX-file to test the installation. Install
184 % the |niceframe| package, and run |latex example.tex|.
185 % \begin{macrocode}
186 %<*example>
187 \documentclass[a4paper]{article}
188 \usepackage{niceframe}
189
190 \begin{document}
191 \pagestyle{empty}
192
193 \parindent 0pt
194 % \end{macrocode}
195 % First, a |\niceframe| that spans the whole |\textwidth|.
196 % \begin{macrocode}
197 \niceframe{%
198 \begin{center}
199 May the road rise to meet you\\
200 May the wind be always at your back\\
201 May the sun shine warm upon your face\\
202 The rain fall soft upon your fields\\
203 And until we meet again\\
204 May God hold you in the hollow of his hand\\
205 \end{center}
206 \bigskip
207 \hfill The Blessing of St.~Patrick
208 }
209 \vfill
210 % \end{macrocode}
211 % Then, a centered |\curlyframe| that is only |0.75\textwidth| wide.
212 % \begin{macrocode}
213 \centerline{%
214 \curlyframe[0.75\textwidth]{%
215 \begin{center}
216 \LARGE I am not flexible!\\
217 Just disorganized!\\
218 \end{center}
219 }}
220 \vfill
221 % \end{macrocode}
222 % And an |\artdecoframe| for the philosophical bit.
223 % \begin{macrocode}
224 \centerline{or is it\dots}
225 \vfill
226 \artdecoframe{%
227 \begin{center}
228 \LARGE I am not disorganized!\\
229 Just flexible!\\
230 \end{center}
231 }
232 \newpage
233 % \end{macrocode}
234 % The following three frames are examples of |\generalframe|.
235 % \begin{macrocode}
236 \font\border=karta15
237 \generalframe{\border\char'307}{\border\char'324}{\border\char'322}
238 {\border\char'310} {\border\char'323}
239 {\border\char'174}{\border\char'325}{\border\char'175}
240 {This is a \texttt{generalframe}, using eight different
241 characters from font \texttt{karta15} as parts of the
242 framework. One might use it to point other people to
243 important notes, hints and/or messages.
244 }
245 \vfill
246 \font\border=umranda
247 \generalframe{\border\char'136}{\border\char'137}{\border\char'140}
248 {\border\char'145} {\border\char'141}
249 {\border\char'144}{\border\char'143}{\border\char'142}
250 {This \texttt{generalframe} uses symbols from Alexander
251 Schrell's \texttt{umranda} (his eMail is:
252 alexander\_ [email protected]) collection.
253 The material to be framed consists of quite a few lines to
254 emphasize the fact that virtually anything can go
255 inside a \texttt{generalframe}. Note that we are limited
256 by \TeX's memory as the material to frame has to be passed
257 as an argument. You can't cheat by passing a \texttt{vbox}
258 that has already been set (as you might with some other
259 macros) since \texttt{generalframe} has to re-set all of it.
260 }
261 \vfill
262 \font\border=umrandb
263 \generalframe{\border\char'165}{\border\char'151}{\border\char'164}%
264 {\border\char'150} {\border\char'150}%
265 {\border\char'166}{\border\char'151}{\border\char'167}
266 {Last, but not least! This \texttt{generalframe} (with
267 symbols from \texttt{umrandb}) displays some math:
268 $$ E = mc^2 $$
269 which everyone will immediately recognize as the famous
270 Einstein formula for energy-mass-equivalence.
271 }
272 \end{document}
273 %</example>
274 % \end{macrocode}
275 %
276 % \subsection{Useful fonts}
277 %
278 % The font used for setting the frames is the \textbf{dingbat} font by
279 % Doug Henderson. Since the original distribution contained a wrongly
280 % coded char, I have included a corrected version with this package.
281 % Except from the code for |char("e")|, this is Doug's original file.
282 %
283 % I have also added the fonts \textbf{bbding10}, \textbf{karta15},
284 % \textbf{umranda} and \textbf{umrandb} for they are used in the examples.
285 %
286 % \StopEventually{\PrintIndex\PrintChanges}
287 %
288 % \subsection{The code}
289 %
290 % We begin by identifying the version of this file on the terminal and
291 % in the transcript fileand by loading the package |calc|.
292 % \begin{macrocode}
293 %<*package>
294 \NeedsTeXFormat{LaTeX2e}[1994/06/01]
295 \ProvidesPackage{niceframe}[\filedate\space v\fileversion\space niceframe package (MO)]
296 \typeout{Package: niceframe v\fileversion\space <\filedate> (Marcus Ohlhaut)}
297 \RequirePackage{calc}
298 % \end{macrocode}
299 % We then load the font used for setting the standard frames.
300 % \begin{macrocode}
301 \font\ding dingbat scaled 1200
302 % \end{macrocode}
303 % A few internal dimensions need to be defined and initialized.
304 % \begin{macrocode}
305 \newlength{\nicefr@mechar}
306 \settowidth{\nicefr@mechar}{\ding\char'141}
307 \newlength{\nicefr@mewidth}
308 \setlength{\nicefr@mewidth}{\hsize}
309 \newlength{\nicefr@meheight}
310 \setlength{\nicefr@meheight}{\vsize}
311 \newlength{\@ldhsize}
312 \setlength{\@ldhsize}{\hsize}
313 % \end{macrocode}
314 % \begin{macro}{\upd@ublerulefill}
315 % \begin{macro}{\dnd@ublerulefill}
316 % \begin{macro}{\ltd@ublerulefill}
317 % \begin{macro}{\rtd@ublerulefill}
318 % These internal macros define a set of leaders for each of the four
319 % sides of |\niceframe|. The appropriate chars are taken from the
320 % \textbf{dingbat} font.
321 % \begin{macrocode}
322 \newcommand{\upd@ublerulefill}{\xleaders\hbox to 10pt
323 {\hss\ding\char'142 \hss}\hfill}
324 \newcommand{\dnd@ublerulefill}{\xleaders\hbox to 10pt
325 {\hss\ding\char'147 \hss}\hfill}
326 \newcommand{\ltd@ublerulefill}{\xleaders\vbox to 10pt
327 {\vss\hbox{\ding\char'144}\vss}\vfill}
328 \newcommand{\rtd@ublerulefill}{\xleaders\vbox to 10pt
329 {\vss\hbox{\ding\char'145}\vss}\vfill}
330 % \end{macrocode}
331 % \end{macro}
332 % \end{macro}
333 % \end{macro}
334 % \end{macro}
335 % \begin{macro}{\niceframe}
336 % Finally, we define the user interfaces.
337 % \begin{macrocode}
338 \newcommand{\niceframe}[2][\textwidth]{{
339 % \end{macrocode}
340 % First, we have to set the material that is passed to |\niceframe| to
341 % an appropriate width. That width is the requested width of the final
342 % |\vbox| minus twice the size of the chars that make up the corners of
343 % the frame (ie.\ |\nicefr@mechar|). The set material is stored for
344 % further use in |\box0|.
345 % \begin{macrocode}
346 \setlength{\hsize}{#1 - 2\nicefr@mechar}
347 \setbox0=\vbox{#2}
348 % \end{macrocode}
349 % We then use height and depth of |\box0| to calculate the required
350 % height of the |\vbox| that encloses the vertical leaders.
351 % \begin{macrocode}
352 \setlength{\nicefr@meheight}{\ht0 + \dp0}
353 % \end{macrocode}
354 % Similarily, we then use the width of |\box0| for enclosing the
355 % horizontal leaders.
356 % \begin{macrocode}
357 \setlength{\nicefr@mewidth}{\wd0 + 2\nicefr@mechar}
358 % \end{macrocode}
359 % Finally, when all the relevant dimensions have been determined, the
360 % frame is compiled. We start with the top row (corner char, horizontal
361 % leader, corner char), set the middle part (vertical leader, things to
362 % frame, vertical leader) and finish with the bottom row (corner char,
363 % horizontal leader, corner char).
364 % \begin{macrocode}
365 \vbox{%
366 \hbox to\nicefr@mewidth{\ding\char'141\upd@ublerulefill\char'143}
367 \hbox to\nicefr@mewidth{\vbox to\nicefr@meheight{\ltd@ublerulefill}
368 \hss\raise\dp0\box0\hss
369 \vbox to\nicefr@meheight{\rtd@ublerulefill}}
370 \hbox to\nicefr@mewidth{\ding\char'146\dnd@ublerulefill\char'150}
371 }
372 }}
373 % \end{macrocode}
374 % \end{macro}
375 % \begin{macro}{\curlyframe}
376 % This macro works exactly like |\niceframe|. The only difference is
377 % that we use stretchable space instead of leaders and different glyphs
378 % for the four corners (obviously). We halso have to move the text a bit
379 % closer to the corners due to their shape.
380 % \begin{macrocode}
381 \newcommand{\curlyframe}[2][\textwidth]{{
382 \setlength{\hsize}{#1 - 2\nicefr@mechar}
383 \setbox0=\vbox{#2}
384 \setlength{\nicefr@meheight}{\ht0 + \dp0}
385 \setlength{\nicefr@mewidth}{\wd0 + 2\nicefr@mechar}
386 \vbox{%
387 \hbox to\nicefr@mewidth{\ding\char'105\hfill\char'106}
388 \vskip-\baselineskip
389 \hbox to\nicefr@mewidth{\hss\raise\dp0\box0\hss}
390 \vskip-\baselineskip
391 \hbox to\nicefr@mewidth{\ding\char'110\hfill\char'107}
392 }
393 }}
394 % \end{macrocode}
395 % \end{macro}
396 % \begin{macro}{\artdecoframe}
397 % This is just a variation of |\curlyframe|.
398 % \begin{macrocode}
399 \newcommand{\artdecoframe}[2][\textwidth]{{
400 \setlength{\hsize}{#1 - 2\nicefr@mechar}
401 \setbox0=\vbox{#2}
402 \setlength{\nicefr@meheight}{\ht0 + \dp0}
403 \setlength{\nicefr@mewidth}{\wd0 + 2\nicefr@mechar}
404 \vbox{%
405 \hbox to\nicefr@mewidth{\ding\char'115\hfill\char'114}
406 \hbox to\nicefr@mewidth{\hss\raise\dp0\box0\hss}
407 \hbox to\nicefr@mewidth{\ding\char'112\hfill\char'113}
408 }
409 }}
410 % \end{macrocode}
411 % \end{macro}
412 % \begin{macro}{\generalframe}
413 % Finally, I have designed a more general macro for framing.
414 % |\generalframe| takes nine parameters (right to the limit) and
415 % produces a |\vbox|. The width of this box is less than (or equal to)
416 % the current |\hsize|; and it consists of a border generated from the
417 % characters in the first eight arguments and a box which contains the
418 % material passed in the very last argument.
419 %
420 % The first eight parameters to |\generalframe| are used as follows:
421 % \begin{itemize}
422 % \item |#1| is the character for the top left corner,
423 % \item |#2| builds the top horizontal leader,
424 % \item |#3| is the character for the top right corner,
425 % \item |#4| builds the left vertical leader,
426 % \item |#5| builds the right vertical leader,
427 % \item |#6| is the character for the bottom left corner,
428 % \item |#7| builds the top horizontal leader,
429 % \item |#8| is the character for the bottom right corner,
430 % \end{itemize}
431 %
432 % This box is centered with respect to the frame, and there is at least
433 % |\fboxsep| between the frame and the enclosed material. To ensure that the
434 % inner box is calculated properly, all the characters for framing need
435 % to be of equal width and height.
436 %
437 % We first define some internal quantities. |times| holds the number
438 % |\hsize| \emph{div} |\fr@mecharTT| which is required in the process
439 % of rounding, |\fr@mecharTT| and |\fr@mecharLL| hold the width and
440 % height of the characters that make up the top/bottom and left/right
441 % parts of the frame, respectively.
442 %
443 % |\fr@mewidth| holds the final width of the frame and is always less than
444 % or equal to the current |\hsize|, whereas |\fr@meheight| holds the
445 % final height of the frame minus the heights of the top and bottom row.
446 % \begin{macrocode}
447 \newcounter{times}
448 \newlength{\fr@mecharTT}
449 \newlength{\fr@mecharLL}
450 \newlength{\fr@mewidth}
451 \newlength{\fr@meheight}
452 % \end{macrocode}
453 % |\generalframe| initializes |\fr@mecharTT| and |\fr@mecharLL| every
454 % time it is called, relying on the fact that the user specifies
455 % the eight border characters in such a way that |#1|, |#2|, |#3|, |#6|,
456 % |#7| and |#8| have the same width and |#1|, |#3|, |#4|, |#5|, |#6| and
457 % |#8| have the same height.
458 % \begin{macrocode}
459 \newcommand{\generalframe}[9]{{
460 \settowidth{\fr@mecharTT}{#2}
461 \settoheight{\fr@mecharLL}{#4}
462 % \end{macrocode}
463 % In order to enable a packed alignment of the horizontal leaders, we
464 % have to round |\fr@mewidth| to an integer multiple of |\fr@mecharTT|.
465 % \begin{macrocode}
466 \setcounter{times}{1 * \ratio{\hsize}{\fr@mecharTT}}
467 \setlength{\fr@mewidth}{\fr@mecharTT * \value{times}}
468 % \end{macrocode}
469 % |\fr@mewidth| is then used to calculate the |\hsize| of the innermost
470 % box, allowing for some horizontal space at either side. The box is set
471 % and stored in |\box0| for later use.
472 % \begin{macrocode}
473 \setlength{\hsize}{\fr@mewidth - 2\fr@mecharTT - 2\fboxsep}
474 \setbox0=\vbox{#9}
475 % \end{macrocode}
476 % We then calculate |\fr@meheight| (height plus depth of |\box0|, with
477 % some vertical space added) and round it to an integer multiple of
478 % |\fr@mecharLL|. We add one to ensure at least one character in the
479 % vertical leaders.
480 % \begin{macrocode}
481 \setlength{\fr@meheight}{\ht0 + \dp0 + 2\fboxsep}
482 \setcounter{times}{1 * \ratio{\fr@meheight}{\fr@mecharLL}}
483 \setcounter{times}{\value{times} + 1}
484 \setlength{\fr@meheight}{\fr@mecharLL * \value{times}}
485 % \end{macrocode}
486 % Four leaders are used to construct the main part of the frame.
487 % \begin{macrocode}
488 \newcommand{\up@fill}{\leaders\hbox{#2}\hfill}
489 \newcommand{\lt@fill}{\leaders\vbox{\hbox{#4}}\vfill}
490 \newcommand{\rt@fill}{\leaders\vbox{\hbox{#5}}\vfill}
491 \newcommand{\dn@fill}{\leaders\hbox{#7}\hfill}
492 % \end{macrocode}
493 % Finally, everthing is packed together, centered nicely.
494 % \begin{macrocode}
495 \vbox{%
496 \hbox to\fr@mewidth{#1\up@fill#3}\nointerlineskip
497 \hbox to\fr@mewidth{\vbox to\fr@meheight{\lt@fill}%
498 \hfill%
499 \vbox to\fr@meheight{\vfill\box0\vfill}%
500 \hfill%
501 \vbox to\fr@meheight{\rt@fill}%
502 }\nointerlineskip
503 \hbox to\fr@mewidth{#6\dn@fill#8}\nointerlineskip
504 }
505 }}
506 % \end{macrocode}
507 % \end{macro}
508 % That's all there is.
509 % \begin{macrocode}
510 %</package>
511 % \end{macrocode}
512 %
513 % \Finale
514 %
515 \endinput