summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/niceframe/niceframe.dtx
blob: 6553db0f32743b6b069a57e80e24c5087cba6512 (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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
% \iffalse meta-comment
%
%  This package is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Marcus Ohlhaut.
%
% This work consists of the files niceframe.dtx and niceframe.ins
% and the derived file niceframe.sty.
%
% Copyright (C) 2009 Marcus Ohlhaut (marcus@ohlhaut.de).
% All rights reserved.
%
% \fi
%% \CharacterTable
%%  {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
%%   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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
\def\fileversion{1.1c}
\def\filedate{2009/31/08}
%
% \CheckSum{282}
%
%\iffalse
%
% Package NiceFrame to be used with LaTeX 2e
% Copyright (C) 1996-2009 Marcus Ohlhaut (marcus@ohlhaut.de).
% All rights reserved.
%
% Error reports for UNCHANGED versions please to:
%                          marcus@ohlhaut.de
%
%\fi
%
% \title{A style option to create nice frames with the \textbf{dingbat}
%        fonts\thanks{This file has version number \fileversion\ --
%        last revision \filedate.}}
%
% \author{Marcus Ohlhaut\\
%         Wertheimer Stra\ss e 59\\
%         D-81243 M\"unchen\\
%         {\tt marcus@ohlhaut.de}}
%
% \date{Printed \today}
% \maketitle
%
% \changes{1.0}{1995/07/08}{Adapted this to LaTeX2e}
% \changes{1.0a}{1995/07/13}{Added CurlyFrame and ArtDecoFrame}
% \changes{1.0b}{1995/07/16}{Fixed documentation}
% \changes{1.0c}{1996/02/11}{Fixed 8+3 names}
% \changes{1.1}{1996/02/20}{Redesign of GeneralFrame}
% \changes{1.1b}{1996/10/20}{Fixed alignment of right vleaders}
% \changes{1.1b}{1996/10/20}{Changed command names to lowercase}
% \changes{1.1b}{1996/10/20}{Adapted installation to new version of docstrip}
% \changes{1.1c}{2009/08/31}{Changed license to LPPL 1.3}
%
% \DoNotIndex{\addtolength,\baselineskip,\begin,\bigskip,\box}
% \DoNotIndex{\centerline,\char,\CodelineIndex,\columnsep,\columnwidth}
% \DoNotIndex{\DocInput,\documentclass,\dots,\dp}
% \DoNotIndex{\EnableCrossrefs,\end}
% \DoNotIndex{\font,\hbox,\headsep,\hfill,\hsize,\hss,\ht}
% \DoNotIndex{\LARGE,\Large,\leaders,\MakeShortVerb,\marginparwidth}
% \DoNotIndex{\NeedsTeXFormat,\newcommand,\newlength,\oddsidemargin}
% \DoNotIndex{\pagestyle,\parindent,\parskip,\pixel,\ProvidesPackage,\pxl}
% \DoNotIndex{\RecordChanges,\setbox,\setlength,\settowidth}
% \DoNotIndex{\textheight,\textwidth,\thin,\topmargin,\typeout}
% \DoNotIndex{\usepackage,\vbox,\vfill,\vsize,\vskip,\vss}
% \DoNotIndex{\wd,\\,\|\ }
%
% \begin{abstract}
%   This article describes a new style option that can be used with the
%   document styles that are distributed with the \LaTeX\ distributions.
%   It defines new commands to frame material with decorative frames,
%   using \textbf{dingbat} fonts.
% \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
%
% When I set out to become familar with all the fonts available for
% \TeX, I came across the \textbf{dingbat} font. Only a few glyphs have
% been defined in that font, and some of them are intended to yield
% nice frames when set appropriately.
%
% I didn't want to work out the details of arranging the glyphs each
% time I needed to frame text, and hence wrote this little package to
% do the work for me.
%
% When testing this, I noticed that one of the glyphs was wrongly coded
% in the original \textbf{dingbat} distribution. Together with this
% package, a corrected version of \textbf{dingbat} is distributed.
%
% This package has no options. It requires the package |calc| by Kresten~K.
% Thorup and Frank Jensen.
%
% \section{The user interface}
% This package defines three commands, |\niceframe|, |\curlyframe| and
% |\artdecoframe|. All three take one mandatory and one optional argument.
% The mandatory argument specifies the material that is to be framed
% (anything which can go into a |\vbox|), whereas the optional argument
% specifies the final width of the frame.
%
% If the optional argument is omitted, the frame will be exactly of
% width |\textwidth|. The height of the frame is calculated from the
% natural height of the enclosed material.
%
% These frames have to be set into their own paragraphs, otherwise the
% width of the surrounding text will not be correct.
%
% The package also defines a more general macro called |\generalframe|
% to allow control over the symbols which are used to build the frame.
%
% \section{The implementation}
% \subsection{The {\sc docstrip} modules}
%
% The following modules are used in the implementation to direct
% {\sc docstrip} in generating the external files:
% \begin{center}
% \begin{tabular}{ll}
%   driver   & produce the documentation driver file \\
%   package  & produce the package file \\
%   example  & produce an example file \\
% \end{tabular}
% \end{center}
%
% \subsection{Producing the documentation}
%
% A short driver is provided that can be extracted (if necessary)
% by the {\sc docstrip} program provided with \LaTeXe.
%    \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}

% dimensions from ltugboat.sty:
\setlength\textwidth{31pc} \setlength\textheight{54pc}
\setlength{\parindent}{0pt}
\setlength{\parskip}{2pt plus 1pt minus 1pt}
\setlength{\oddsidemargin}{8pc}
\setlength{\marginparwidth}{8pc}
\setlength{\topmargin}{-2.5pc}
\setlength{\headsep}{20pt}
\setlength{\columnsep}{1.5pc}
\setlength{\columnwidth}{18.75pc}
\EnableCrossrefs
\RecordChanges
\CodelineIndex

\MakeShortVerb{\|}
\begin{document}

\DocInput{niceframe.dtx}

\end{document}
%</driver>
%    \end{macrocode}
%
% \subsection{The example}
%
% This is just a short \LaTeX-file to test the installation. Install
% the |niceframe| package, and run |latex example.tex|.
%    \begin{macrocode}
%<*example>
\documentclass[a4paper]{article}
\usepackage{niceframe}

\begin{document}
\pagestyle{empty}

\parindent 0pt
%    \end{macrocode}
% First, a |\niceframe| that spans the whole |\textwidth|.
%    \begin{macrocode}
\niceframe{%
 \begin{center}
  May the road rise to meet you\\
  May the wind be always at your back\\
  May the sun shine warm upon your face\\
  The rain fall soft upon your fields\\
  And until we meet again\\
  May God hold you in the hollow of his hand\\
 \end{center}
 \bigskip
 \hfill The Blessing of St.~Patrick
}
\vfill
%    \end{macrocode}
% Then, a centered |\curlyframe| that is only |0.75\textwidth| wide.
%    \begin{macrocode}
\centerline{%
 \curlyframe[0.75\textwidth]{%
  \begin{center}
   \LARGE I am not flexible!\\
   Just disorganized!\\
  \end{center}
}}
\vfill
%    \end{macrocode}
% And an |\artdecoframe| for the philosophical bit.
%    \begin{macrocode}
\centerline{or is it\dots}
\vfill
\artdecoframe{%
 \begin{center}
  \LARGE I am not disorganized!\\
  Just flexible!\\
 \end{center}
}
\newpage
%    \end{macrocode}
% The following three frames are examples of |\generalframe|.
%    \begin{macrocode}
\font\border=karta15
\generalframe{\border\char'307}{\border\char'324}{\border\char'322}
             {\border\char'310}                  {\border\char'323}
             {\border\char'174}{\border\char'325}{\border\char'175}
             {This is a \texttt{generalframe}, using eight different
              characters from font \texttt{karta15} as parts of the
              framework. One might use it to point other people to
              important notes, hints and/or messages.
             }
\vfill
\font\border=umranda
\generalframe{\border\char'136}{\border\char'137}{\border\char'140}
             {\border\char'145}                  {\border\char'141}
             {\border\char'144}{\border\char'143}{\border\char'142}
             {This \texttt{generalframe} uses symbols from Alexander
              Schrell's \texttt{umranda} (his eMail is:
              alexander\_ schrell@w2.maus.de) collection.
              The material to be framed consists of quite a few lines to
              emphasize the fact that virtually anything can go
              inside a \texttt{generalframe}. Note that we are limited
              by \TeX's memory as the material to frame has to be passed
              as an argument. You can't cheat by passing a \texttt{vbox}
              that has already been set (as you might with some other
              macros) since \texttt{generalframe} has to re-set all of it.
             }
\vfill
\font\border=umrandb
\generalframe{\border\char'165}{\border\char'151}{\border\char'164}%
             {\border\char'150}                  {\border\char'150}%
             {\border\char'166}{\border\char'151}{\border\char'167}
             {Last, but not least! This \texttt{generalframe} (with
              symbols from \texttt{umrandb}) displays some math:
              $$ E = mc^2 $$
              which everyone will immediately recognize as the famous
              Einstein formula for energy-mass-equivalence.
             }
\end{document}
%</example>
%    \end{macrocode}
%
% \subsection{Useful fonts}
%
% The font used for setting the frames is the \textbf{dingbat} font by
% Doug Henderson. Since the original distribution contained a wrongly
% coded char, I have included a corrected version with this package.
% Except from the code for |char("e")|, this is Doug's original file.
%
% I have also added the fonts \textbf{bbding10}, \textbf{karta15},
% \textbf{umranda} and \textbf{umrandb} for they are used in the examples.
%
% \StopEventually{\PrintIndex\PrintChanges}
%
% \subsection{The code}
%
% We begin by identifying the version of this file on the terminal and
% in the transcript fileand by loading the package |calc|.
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{niceframe}[\filedate\space v\fileversion\space niceframe package (MO)]
\typeout{Package: niceframe v\fileversion\space <\filedate> (Marcus Ohlhaut)}
\RequirePackage{calc}
%    \end{macrocode}
% We then load the font used for setting the standard frames.
%    \begin{macrocode}
\font\ding dingbat scaled 1200
%    \end{macrocode}
% A few internal dimensions need to be defined and initialized.
%    \begin{macrocode}
\newlength{\nicefr@mechar}
\settowidth{\nicefr@mechar}{\ding\char'141}
\newlength{\nicefr@mewidth}
\setlength{\nicefr@mewidth}{\hsize}
\newlength{\nicefr@meheight}
\setlength{\nicefr@meheight}{\vsize}
\newlength{\@ldhsize}
\setlength{\@ldhsize}{\hsize}
%    \end{macrocode}
% \begin{macro}{\upd@ublerulefill}
% \begin{macro}{\dnd@ublerulefill}
% \begin{macro}{\ltd@ublerulefill}
% \begin{macro}{\rtd@ublerulefill}
% These internal macros define a set of leaders for each of the four
% sides of |\niceframe|. The appropriate chars are taken from the
% \textbf{dingbat} font.
%    \begin{macrocode}
\newcommand{\upd@ublerulefill}{\xleaders\hbox to 10pt
 {\hss\ding\char'142 \hss}\hfill}
\newcommand{\dnd@ublerulefill}{\xleaders\hbox to 10pt
 {\hss\ding\char'147 \hss}\hfill}
\newcommand{\ltd@ublerulefill}{\xleaders\vbox to 10pt
 {\vss\hbox{\ding\char'144}\vss}\vfill}
\newcommand{\rtd@ublerulefill}{\xleaders\vbox to 10pt
 {\vss\hbox{\ding\char'145}\vss}\vfill}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\niceframe}
% Finally, we define the user interfaces.
%    \begin{macrocode}
\newcommand{\niceframe}[2][\textwidth]{{
%    \end{macrocode}
% First, we have to set the material that is passed to |\niceframe| to
% an appropriate width. That width is the requested width of the final
% |\vbox| minus twice the size of the chars that make up the corners of
% the frame (ie.\ |\nicefr@mechar|). The set material is stored for
% further use in |\box0|.
%    \begin{macrocode}
 \setlength{\hsize}{#1 - 2\nicefr@mechar}
 \setbox0=\vbox{#2}
%    \end{macrocode}
% We then use height and depth of |\box0| to calculate the required
% height of the |\vbox| that encloses the vertical leaders.
%    \begin{macrocode}
 \setlength{\nicefr@meheight}{\ht0 + \dp0}
%    \end{macrocode}
% Similarily, we then use the width of |\box0| for enclosing the
% horizontal leaders.
%    \begin{macrocode}
 \setlength{\nicefr@mewidth}{\wd0 + 2\nicefr@mechar}
%    \end{macrocode}
% Finally, when all the relevant dimensions have been determined, the
% frame is compiled. We start with the top row (corner char, horizontal
% leader, corner char), set the middle part (vertical leader, things to
% frame, vertical leader) and finish with the bottom row (corner char,
% horizontal leader, corner char).
%    \begin{macrocode}
 \vbox{%
  \hbox to\nicefr@mewidth{\ding\char'141\upd@ublerulefill\char'143}
  \hbox to\nicefr@mewidth{\vbox to\nicefr@meheight{\ltd@ublerulefill}
                          \hss\raise\dp0\box0\hss
                          \vbox to\nicefr@meheight{\rtd@ublerulefill}}
  \hbox to\nicefr@mewidth{\ding\char'146\dnd@ublerulefill\char'150}
 }
}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\curlyframe}
% This macro works exactly like |\niceframe|. The only difference is
% that we use stretchable space instead of leaders and different glyphs
% for the four corners (obviously). We halso have to move the text a bit
% closer to the corners due to their shape.
%    \begin{macrocode}
\newcommand{\curlyframe}[2][\textwidth]{{
 \setlength{\hsize}{#1 - 2\nicefr@mechar}
 \setbox0=\vbox{#2}
 \setlength{\nicefr@meheight}{\ht0 + \dp0}
 \setlength{\nicefr@mewidth}{\wd0 + 2\nicefr@mechar}
 \vbox{%
  \hbox to\nicefr@mewidth{\ding\char'105\hfill\char'106}
  \vskip-\baselineskip
  \hbox to\nicefr@mewidth{\hss\raise\dp0\box0\hss}
  \vskip-\baselineskip
  \hbox to\nicefr@mewidth{\ding\char'110\hfill\char'107}
 }
}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\artdecoframe}
% This is just a variation of |\curlyframe|.
%    \begin{macrocode}
\newcommand{\artdecoframe}[2][\textwidth]{{
 \setlength{\hsize}{#1 - 2\nicefr@mechar}
 \setbox0=\vbox{#2}
 \setlength{\nicefr@meheight}{\ht0 + \dp0}
 \setlength{\nicefr@mewidth}{\wd0 + 2\nicefr@mechar}
 \vbox{%
  \hbox to\nicefr@mewidth{\ding\char'115\hfill\char'114}
  \hbox to\nicefr@mewidth{\hss\raise\dp0\box0\hss}
  \hbox to\nicefr@mewidth{\ding\char'112\hfill\char'113}
 }
}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\generalframe}
% Finally, I have designed a more general macro for framing.
% |\generalframe| takes nine parameters (right to the limit) and
% produces a |\vbox|. The width of this box is less than (or equal to)
% the current |\hsize|; and it consists of a border generated from the
% characters in the first eight arguments and a box which contains the
% material passed in the very last argument.
%
% The first eight parameters to |\generalframe| are used as follows:
% \begin{itemize}
% \item |#1| is the character for the top left corner,
% \item |#2| builds the top horizontal leader,
% \item |#3| is the character for the top right corner,
% \item |#4| builds the left vertical leader,
% \item |#5| builds the right vertical leader,
% \item |#6| is the character for the bottom left corner,
% \item |#7| builds the top horizontal leader,
% \item |#8| is the character for the bottom right corner,
% \end{itemize}
%
% This box is centered with respect to the frame, and there is at least
% |\fboxsep| between the frame and the enclosed material. To ensure that the
% inner box is calculated properly, all the characters for framing need
% to be of equal width and height.
%
% We first define some internal quantities. |times| holds the number
% |\hsize| \emph{div} |\fr@mecharTT| which is required in the process
% of rounding, |\fr@mecharTT| and |\fr@mecharLL| hold the width and
% height of the characters that make up the top/bottom and left/right
% parts of the frame, respectively.
%
% |\fr@mewidth| holds the final width of the frame and is always less than
% or equal to the current |\hsize|, whereas |\fr@meheight| holds the
% final height of the frame minus the heights of the top and bottom row.
%    \begin{macrocode}
\newcounter{times}
\newlength{\fr@mecharTT}
\newlength{\fr@mecharLL}
\newlength{\fr@mewidth}
\newlength{\fr@meheight}
%    \end{macrocode}
% |\generalframe| initializes |\fr@mecharTT| and |\fr@mecharLL| every
% time it is called, relying on the fact that the user specifies
% the eight border characters in such a way that |#1|, |#2|, |#3|, |#6|,
% |#7| and |#8| have the same width and |#1|, |#3|, |#4|, |#5|, |#6| and
% |#8| have the same height.
%    \begin{macrocode}
\newcommand{\generalframe}[9]{{
 \settowidth{\fr@mecharTT}{#2}
 \settoheight{\fr@mecharLL}{#4}
%    \end{macrocode}
% In order to enable a packed alignment of the horizontal leaders, we
% have to round |\fr@mewidth| to an integer multiple of |\fr@mecharTT|.
%    \begin{macrocode}
 \setcounter{times}{1 * \ratio{\hsize}{\fr@mecharTT}}
 \setlength{\fr@mewidth}{\fr@mecharTT * \value{times}}
%    \end{macrocode}
% |\fr@mewidth| is then used to calculate the |\hsize| of the innermost
% box, allowing for some horizontal space at either side. The box is set
% and stored in |\box0| for later use.
%    \begin{macrocode}
 \setlength{\hsize}{\fr@mewidth - 2\fr@mecharTT - 2\fboxsep}
 \setbox0=\vbox{#9}
%    \end{macrocode}
% We then calculate |\fr@meheight| (height plus depth of |\box0|, with
% some vertical space added) and round it to an integer multiple of
% |\fr@mecharLL|. We add one to ensure at least one character in the
% vertical leaders.
%    \begin{macrocode}
 \setlength{\fr@meheight}{\ht0 + \dp0 + 2\fboxsep}
 \setcounter{times}{1 * \ratio{\fr@meheight}{\fr@mecharLL}}
 \setcounter{times}{\value{times} + 1}
 \setlength{\fr@meheight}{\fr@mecharLL * \value{times}}
%    \end{macrocode}
% Four leaders are used to construct the main part of the frame.
%    \begin{macrocode}
 \newcommand{\up@fill}{\leaders\hbox{#2}\hfill}
 \newcommand{\lt@fill}{\leaders\vbox{\hbox{#4}}\vfill}
 \newcommand{\rt@fill}{\leaders\vbox{\hbox{#5}}\vfill}
 \newcommand{\dn@fill}{\leaders\hbox{#7}\hfill}
%    \end{macrocode}
% Finally, everthing is packed together, centered nicely.
%    \begin{macrocode}
 \vbox{%
 \hbox to\fr@mewidth{#1\up@fill#3}\nointerlineskip
 \hbox to\fr@mewidth{\vbox to\fr@meheight{\lt@fill}%
                     \hfill%
                     \vbox to\fr@meheight{\vfill\box0\vfill}%
                     \hfill%
                     \vbox to\fr@meheight{\rt@fill}%
                    }\nointerlineskip
 \hbox to\fr@mewidth{#6\dn@fill#8}\nointerlineskip
 }
}}
%    \end{macrocode}
% \end{macro}
% That's all there is.
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \Finale
%
\endinput