summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/genmpage/genmpage.dtx
blob: 2b8019bb61b50a993820d88578f4bc7a2a0987c7 (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
% \iffalse
%%
%%
%% Copyright (C) 2001-2006 Thomas Lotze
%%
%% This file may be distributed under the terms of the LaTeX Project
%% Public License, as described in lppl.txt in the base LaTeX
%% distribution. Either version 1.3c or, at your option, any later
%% version.
%%
%<*dtx>
          \ProvidesFile{genmpage.dtx}
          [2006/09/16 Generalized minipage environment (Thomas Lotze)]
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{genmpage}[2006/09/16 Generalized minipage environment (Thomas Lotze)]
%<package>\RequirePackage{keyval}
%<driver> \ProvidesFile{genmpage.drv}
% \fi
%
% \iffalse
%<*driver>
\documentclass{ltxdoc}
\usepackage{genmpage}
\addtolength{\oddsidemargin}{-1cm}
\addtolength{\textwidth}{2cm}
\begin{document}
\DocInput{genmpage.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{genmpage.dtx}
%
% \changes{v0.3.1}{2006/09/16}
%    {Some changes to the doc, bumping license to 1.3c.}
% \changes{v0.3}{2001/02/16}
%    {Addition of |parindent| and |keepparindent| as well as vertical
%     alignment options |T| and |B|. Some changes to the doc.}
% \changes{v0.2}{2001/01/23}
%    {\LaTeX's minipages replaced, minipage parameters accessible as keys, documentation}
% \changes{v0.1}{2001/01/16}
%    {Initial version}
% \marginparsep0pt
%
% \MakeShortVerb{|}
%
% \title{The |genmpage| Package\\-- Generalized minipages --}
% \author{Thomas Lotze}
% \date{\filedate}
% \maketitle
%
% \section{Introduction}
%
% The purpose of this small package is to make \LaTeX's minipages
% more flexible. It is now possible to define styles which determine
% many of the design parameters of a minipage. Such styles can be
% used by calling the |minipage| environment with an additional
% optional argument.
%
% The issue arose from a usenet discussion in |de.comp.text.tex|:
% someone needed to typeset the content of all minipages in a
% document |\raggedright| when he switched to |\raggedright|
% typesetting of the document's body text. This normally
% requires either placing a |\raggedright| in every |minipage|
% environment (which is tedious, error-prone, and has little to
% do with logical mark-up), or defining a new environment (which
% is impractical for everyday use because of the optional argument
% structure of the |minipage| environment).
%
% Other than the justification of a minipage's contents, the
% minipage styles introduced by this package can be used to preset
% its font parameters (family, series, shape, size), the horizontal
% and vertical minipage size, the inner and outer vertical
% alignment parameters, and the indentation of paragraphs.
% Furthermore, two options for the vertical alignment are
% introduced in order to align adjacent minipages with respect
% to their real (visual) top and bottom margins.
%
% The |genmpage| package has been written for \LaTeXe. As the
% published experimental code for \LaTeX\ 3 shows, there will
% be the concept of templates which might well
% render this package useless. At least, it will be both
% necessary and convenient to re-implement it in terms of
% templates.
%
% Please feel free to send suggestions, bug reports, or any
% comments whatsoever concerning this package and its documentation
% to the author at |thomas@thomas-lotze.de|, or via usenet news
% in |de.comp.text.tex| or |comp.text.tex|. The package is developed in a
% subversion repository at
% |https://svn.thomas-lotze.de/repos/public/genmpage/|, releases being
% published on the CTAN.
%
% \section{Usage}
%
% As already mentioned, the |minipage| environment as redefined
% by the |genmpage| package takes another optional argument
% which contains the new parameter settings. In order to preserve
% the argument structure of the usual |minipage| environment,
% this new optional argument comes last. This way, if the
% |genmpage| package is loaded but no values are preset, a
% |minipage| environment without the new argument acts exactly
% as if the package was not present in the first place.
%
% \subsection{Keys}
%
% The new argument is evaluated as a |key=value| list. The usual
% requirements of the |keyval| package hold. The following keys
% are defined:
% 
% \begin{description}
%
% \item[|flush|, |raggedright|, |RaggedRight|, |raggedleft|, |center|:]
% These keys are given without values and determine the
% justification of the minipages contents in the obvious way.
% If |RaggedRight| is used, the |ragged2e| package must be
% loaded. This is not provided for by the |genmpage| package.
%
% \item[|ffamily|, |fseries|, |fshape|:]
% These keys determine the font family, series, and shape of
% the text inside the minipage. They must be given the same
% values as the corresponding |NFSS| commands |\fontfamily|,
% |\fontseries|, and |\fontshape|, resp.
%
% \item[|resetfont|:]
% This key doesn't require a value. If it is given, a
% |\normalfont| is issued before the other font selection
% commands.
%
% \item[|fsize|:]
% A key to determine the font size. Possible values are the
% usual size commands without the backslash, e.g.\@
% |fsize=small|.
%
% \item[|width|, |height|, |outer|, |inner|:]
% Width, height, and outer and inner vertical alignment of
% the minipage (taken as values to these keys). If these keys
% are set, either directly in the optional argument of the
% |minipage| environment, in the preamble, or by using styles
% (see below), they override the values given by the usual
% |minipage| arguments.
%
% \item[|widtharg|, |heightarg|, |outerarg|, |innerarg|:]
% Not requiring values, these keys stop the respective keys
% for width, height, and alignment from taking precedence
% over the usual |minipage| arguments.
% 
% \item[|parindent|, |keepparindent|:]
% \LaTeX\ sets |\parindent| to zero within a minipage.
% If the |parindent| key is set, its value is used for
% |\parindent| instead. This value can be any \LaTeX\ length.
% If |keepparindent| is set (without values), the paragraph
% indentation valid outside the minipage is also used within.
%
% \end{description}
%
% Other than in the new optional argument of the |minipage|
% environment, all keys can be set by the |keyval| command
% |\setkeys|, for instance:
%
% \medskip
% |\setkeys{GenMP}{height=0.3\textheight,resetfont,fshape=it,inner=s}|
% \medskip
%
% \subsection{New options for vertical alignment}
%
% Following a suggestion by Donald Arseneau (thanks!), I've
% introduced two new options for the outer vertical alignment
% of minipages. With the options |T| and |B|, minipages are
% aligned with respect to their visual margins as opposed to
% the baselines of the first or last line of text, resp. This
% will come in most handy if a minipage starts with an image.
%
% As the |genmpage| package doesn't try to fiddle with \LaTeX's
% way of digesting alignment options, it recognizes the |T| and
% |B| options, inserts a |\vspace{0pt}| command at the beginning
% or end of the minipage, and passes on a |t| or |b| option.
% Therefore, |T| and |B| can only be used as values to the
% |genmpage| package's |inner| key but not as one of the
% traditional alignment arguments of minipages.
%
% \subsection{Styles}
%
% \DescribeMacro
%  \defineMPstyle\marg{style}\marg{definitions}\\
% A minipage style is more or less a shorthand for a series
% of |key=value| (or |key|) definitions. Any minipage style
% defined by |\defineMPstyle| can be used as a key without a
% value either in the |minipage| argument, |setkey| commands,
% or even other style definitions. |\defineMPstyle| silently
% redefines a style already existent. An example:
%
% \medskip
% |\defineMPstyle{comment}{resetfont,fsize=small,width=0.2\textwidth}|
% \medskip
%
% There is one style predefined: |\defineMPstyle}{plain}{}|.
% The |plain| style is called before all other definitions.
% Redefining it will change the behaviour of all minipages
% concerning those parameters which are not set either explicitly
% or by using a style or |setkeys| command. As \TeX\ knows no
% command for switching back to justified text, things like
% |\raggedright| cannot be overridden later and should therefore
% be used in the |plain| style with great care.
%
% \section{To do}
% 
% \begin{itemize}
% \item
% Further testing
% \item
% Improving the documentation, in particular including a section
% with usage examples
% \item
% Implementing some frame and color features
% \end{itemize}
%
% \section{Implementation}
%
%    \begin{macrocode}
\newlength\@GenMPparindent

\def\@iiiminipage#1#2[#3]#4{%
  \@ifnextchar[%
    {\@ivminipage{#1}{#2}{#3}{#4}}
    {\@ivminipage{#1}{#2}{#3}{#4}[]}}

\def\@ivminipage#1#2#3#4[#5]{%
  \setkeys{GenMP}{plain,#5}%
  \if@GenMPwidth\else\@GenMPwidth#4\fi
  \if@GenMPheight\else
    \def\@GenMPtempa{#2}\def\@GenMPtempb{\relax}%
    \ifx\@GenMPtempa\@GenMPtempb%
      \let\@GenMPheight=\relax
    \else
      \def\@GenMPheight{#2}%
    \fi
  \fi
  \if@GenMPouter\else\def\@GenMPouter{#1}\fi%
  \if@GenMPinner\else\def\@GenMPinner{#3}\fi%
  \@GenMPparindent\parindent
  \leavevmode
  \@pboxswfalse
  \@tempdima\@GenMPwidth
  \def\@mpargs{{\@GenMPouter}{\@GenMPheight}[\@GenMPinner]{\@GenMPwidth}}%
  \setbox\@tempboxa\vbox\bgroup
    \color@begingroup
      \hsize\@tempdima
      \textwidth\hsize \columnwidth\hsize
      \@parboxrestore
      \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
      \let\@footnotetext\@mpfootnotetext
      \let\@listdepth\@mplistdepth \@mplistdepth\z@
      \@minipagerestore
      \@setminipage}

\def\@setminipage{%
  \@minipagetrue
  \@GenMPtop
  \@GenMPflush  
  \@GenMPresetfont
  \@GenMPffamily\@GenMPfseries\@GenMPfshape\selectfont
  \@GenMPfsize
  \@GenMPsetpi
  \everypar{\@minipagefalse\everypar{}}}

\let\@GenMPendminipage\endminipage
\def\endminipage{%
  \@GenMPbottom
  \@GenMPendminipage}

\let\@GenMPflush=\relax
\define@key{GenMP}{flush}[]{\let\@GenMPflush=\relax}
\define@key{GenMP}{raggedright}[]{\let\@GenMPflush=\raggedright}
\define@key{GenMP}{RaggedRight}[]{\let\@GenMPflush=\RaggedRight}
\define@key{GenMP}{raggedleft}[]{\let\@GenMPflush=\raggedleft}
\define@key{GenMP}{center}[]{\let\@GenMPflush=\centering}

\let\@GenMPffamily=\relax
\let\@GenMPfseries=\relax
\let\@GenMPfshape=\relax
\let\@GenMPresetfont=\relax
\let\@GenMPfsize=\relax
\define@key{GenMP}{ffamily}{\def\@GenMPffamily{\fontfamily{#1}}}
\define@key{GenMP}{fseries}{\def\@GenMPfseries{\fontseries{#1}}}
\define@key{GenMP}{fshape}{\def\@GenMPfshape{\fontshape{#1}}}
\define@key{GenMP}{resetfont}[true]{%  
  \def\@GenMPread{#1}\def\@GenMPtempa{true}%
  \ifx\@GenMPread\@GenMPtempa%
    \let\@GenMPresetfont=\normalfont
  \else
    \let\@GenMPresetfont=\relax
  \fi}
\define@key{GenMP}{fsize}{\def\@GenMPfsize{\csname #1\endcsname}}

\let\@GenMPsetpi=\relax
\define@key{GenMP}{keepparindent}[true]{%  
  \def\@GenMPread{#1}\def\@GenMPtempa{true}%
  \ifx\@GenMPread\@GenMPtempa%
    \def\@GenMPsetpi{\parindent\@GenMPparindent}%
  \fi}
\define@key{GenMP}{parindent}{\def\@GenMPsetpi{\parindent#1}}

\newlength\@GenMPwidth
\newif\if@GenMPwidth
\let\if@GenMPwidth\iffalse
\define@key{GenMP}{width}{\let\if@GenMPwidth\iftrue\@GenMPwidth#1}
\define@key{GenMP}{widtharg}[]{\let\if@GenMPwidth\iffalse}
\newif\if@GenMPheight
\let\if@GenMPheight\iffalse
\define@key{GenMP}{height}{\let\if@GenMPheight\iftrue\def\@GenMPheight{#1}}
\define@key{GenMP}{heightarg}[]{\let\if@GenMPheight\iffalse}

\newif\if@GenMPouter
\let\if@GenMPouter\iffalse
\let\@GenMPtop=\relax
\let\@GenMPbottom=\relax
\define@key{GenMP}{outer}{%
  \def\@GenMPread{#1}\def\@GenMPtempa{T}%
  \ifx\@GenMPread\@GenMPtempa%
    \def\@GenMPtop{\vspace{0pt}}%
    \def\@GenMPouter{t}%
  \else
    \def\@GenMPtempa{B}%
    \ifx\@GenMPread\@GenMPtempa%
      \def\@GenMPbottom{\vspace{0pt}}%
      \def\@GenMPouter{b}%
    \else
      \def\@GenMPouter{#1}%
    \fi
  \fi
  \let\if@GenMPouter\iftrue
}
\define@key{GenMP}{outerarg}[]{\let\if@GenMPouter\iffalse}

\newif\if@GenMPinner
\let\if@GenMPinner\iffalse
\define@key{GenMP}{inner}{\let\if@GenMPinner\iftrue\def\@GenMPinner{#1}}
\define@key{GenMP}{innerarg}[]{\let\if@GenMPinner\iffalse}

\def\defineMPstyle#1#2{%
  \define@key{GenMP}{#1}[]{\setkeys{GenMP}{#2}}}

\defineMPstyle{plain}{}
%    \end{macrocode}
%
% \Finale
%
\endinput
%
% end of file `genmpage.dtx'