Debian Codegraph @

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

raw
1 % \iffalse
2 %%
3 %%
4 %% Copyright (C) 2001-2006 Thomas Lotze
5 %%
6 %% This file may be distributed under the terms of the LaTeX Project
7 %% Public License, as described in lppl.txt in the base LaTeX
8 %% distribution. Either version 1.3c or, at your option, any later
9 %% version.
10 %%
11 %<*dtx>
12 \ProvidesFile{genmpage.dtx}
13 [2006/09/16 Generalized minipage environment (Thomas Lotze)]
14 %</dtx>
15 %<package>\NeedsTeXFormat{LaTeX2e}
16 %<package>\ProvidesPackage{genmpage}[2006/09/16 Generalized minipage environment (Thomas Lotze)]
17 %<package>\RequirePackage{keyval}
18 %<driver> \ProvidesFile{genmpage.drv}
19 % \fi
20 %
21 % \iffalse
22 %<*driver>
23 \documentclass{ltxdoc}
24 \usepackage{genmpage}
25 \addtolength{\oddsidemargin}{-1cm}
26 \addtolength{\textwidth}{2cm}
27 \begin{document}
28 \DocInput{genmpage.dtx}
29 \end{document}
30 %</driver>
31 % \fi
32 %
33 % \GetFileInfo{genmpage.dtx}
34 %
35 % \changes{v0.3.1}{2006/09/16}
36 % {Some changes to the doc, bumping license to 1.3c.}
37 % \changes{v0.3}{2001/02/16}
38 % {Addition of |parindent| and |keepparindent| as well as vertical
39 % alignment options |T| and |B|. Some changes to the doc.}
40 % \changes{v0.2}{2001/01/23}
41 % {\LaTeX's minipages replaced, minipage parameters accessible as keys, documentation}
42 % \changes{v0.1}{2001/01/16}
43 % {Initial version}
44 % \marginparsep0pt
45 %
46 % \MakeShortVerb{|}
47 %
48 % \title{The |genmpage| Package\\-- Generalized minipages --}
49 % \author{Thomas Lotze}
50 % \date{\filedate}
51 % \maketitle
52 %
53 % \section{Introduction}
54 %
55 % The purpose of this small package is to make \LaTeX's minipages
56 % more flexible. It is now possible to define styles which determine
57 % many of the design parameters of a minipage. Such styles can be
58 % used by calling the |minipage| environment with an additional
59 % optional argument.
60 %
61 % The issue arose from a usenet discussion in |de.comp.text.tex|:
62 % someone needed to typeset the content of all minipages in a
63 % document |\raggedright| when he switched to |\raggedright|
64 % typesetting of the document's body text. This normally
65 % requires either placing a |\raggedright| in every |minipage|
66 % environment (which is tedious, error-prone, and has little to
67 % do with logical mark-up), or defining a new environment (which
68 % is impractical for everyday use because of the optional argument
69 % structure of the |minipage| environment).
70 %
71 % Other than the justification of a minipage's contents, the
72 % minipage styles introduced by this package can be used to preset
73 % its font parameters (family, series, shape, size), the horizontal
74 % and vertical minipage size, the inner and outer vertical
75 % alignment parameters, and the indentation of paragraphs.
76 % Furthermore, two options for the vertical alignment are
77 % introduced in order to align adjacent minipages with respect
78 % to their real (visual) top and bottom margins.
79 %
80 % The |genmpage| package has been written for \LaTeXe. As the
81 % published experimental code for \LaTeX\ 3 shows, there will
82 % be the concept of templates which might well
83 % render this package useless. At least, it will be both
84 % necessary and convenient to re-implement it in terms of
85 % templates.
86 %
87 % Please feel free to send suggestions, bug reports, or any
88 % comments whatsoever concerning this package and its documentation
89 % to the author at |[email protected]|, or via usenet news
90 % in |de.comp.text.tex| or |comp.text.tex|. The package is developed in a
91 % subversion repository at
92 % |https://svn.thomas-lotze.de/repos/public/genmpage/|, releases being
93 % published on the CTAN.
94 %
95 % \section{Usage}
96 %
97 % As already mentioned, the |minipage| environment as redefined
98 % by the |genmpage| package takes another optional argument
99 % which contains the new parameter settings. In order to preserve
100 % the argument structure of the usual |minipage| environment,
101 % this new optional argument comes last. This way, if the
102 % |genmpage| package is loaded but no values are preset, a
103 % |minipage| environment without the new argument acts exactly
104 % as if the package was not present in the first place.
105 %
106 % \subsection{Keys}
107 %
108 % The new argument is evaluated as a |key=value| list. The usual
109 % requirements of the |keyval| package hold. The following keys
110 % are defined:
111 %
112 % \begin{description}
113 %
114 % \item[|flush|, |raggedright|, |RaggedRight|, |raggedleft|, |center|:]
115 % These keys are given without values and determine the
116 % justification of the minipages contents in the obvious way.
117 % If |RaggedRight| is used, the |ragged2e| package must be
118 % loaded. This is not provided for by the |genmpage| package.
119 %
120 % \item[|ffamily|, |fseries|, |fshape|:]
121 % These keys determine the font family, series, and shape of
122 % the text inside the minipage. They must be given the same
123 % values as the corresponding |NFSS| commands |\fontfamily|,
124 % |\fontseries|, and |\fontshape|, resp.
125 %
126 % \item[|resetfont|:]
127 % This key doesn't require a value. If it is given, a
128 % |\normalfont| is issued before the other font selection
129 % commands.
130 %
131 % \item[|fsize|:]
132 % A key to determine the font size. Possible values are the
133 % usual size commands without the backslash, e.g.\@
134 % |fsize=small|.
135 %
136 % \item[|width|, |height|, |outer|, |inner|:]
137 % Width, height, and outer and inner vertical alignment of
138 % the minipage (taken as values to these keys). If these keys
139 % are set, either directly in the optional argument of the
140 % |minipage| environment, in the preamble, or by using styles
141 % (see below), they override the values given by the usual
142 % |minipage| arguments.
143 %
144 % \item[|widtharg|, |heightarg|, |outerarg|, |innerarg|:]
145 % Not requiring values, these keys stop the respective keys
146 % for width, height, and alignment from taking precedence
147 % over the usual |minipage| arguments.
148 %
149 % \item[|parindent|, |keepparindent|:]
150 % \LaTeX\ sets |\parindent| to zero within a minipage.
151 % If the |parindent| key is set, its value is used for
152 % |\parindent| instead. This value can be any \LaTeX\ length.
153 % If |keepparindent| is set (without values), the paragraph
154 % indentation valid outside the minipage is also used within.
155 %
156 % \end{description}
157 %
158 % Other than in the new optional argument of the |minipage|
159 % environment, all keys can be set by the |keyval| command
160 % |\setkeys|, for instance:
161 %
162 % \medskip
163 % |\setkeys{GenMP}{height=0.3\textheight,resetfont,fshape=it,inner=s}|
164 % \medskip
165 %
166 % \subsection{New options for vertical alignment}
167 %
168 % Following a suggestion by Donald Arseneau (thanks!), I've
169 % introduced two new options for the outer vertical alignment
170 % of minipages. With the options |T| and |B|, minipages are
171 % aligned with respect to their visual margins as opposed to
172 % the baselines of the first or last line of text, resp. This
173 % will come in most handy if a minipage starts with an image.
174 %
175 % As the |genmpage| package doesn't try to fiddle with \LaTeX's
176 % way of digesting alignment options, it recognizes the |T| and
177 % |B| options, inserts a |\vspace{0pt}| command at the beginning
178 % or end of the minipage, and passes on a |t| or |b| option.
179 % Therefore, |T| and |B| can only be used as values to the
180 % |genmpage| package's |inner| key but not as one of the
181 % traditional alignment arguments of minipages.
182 %
183 % \subsection{Styles}
184 %
185 % \DescribeMacro
186 % \defineMPstyle\marg{style}\marg{definitions}\\
187 % A minipage style is more or less a shorthand for a series
188 % of |key=value| (or |key|) definitions. Any minipage style
189 % defined by |\defineMPstyle| can be used as a key without a
190 % value either in the |minipage| argument, |setkey| commands,
191 % or even other style definitions. |\defineMPstyle| silently
192 % redefines a style already existent. An example:
193 %
194 % \medskip
195 % |\defineMPstyle{comment}{resetfont,fsize=small,width=0.2\textwidth}|
196 % \medskip
197 %
198 % There is one style predefined: |\defineMPstyle}{plain}{}|.
199 % The |plain| style is called before all other definitions.
200 % Redefining it will change the behaviour of all minipages
201 % concerning those parameters which are not set either explicitly
202 % or by using a style or |setkeys| command. As \TeX\ knows no
203 % command for switching back to justified text, things like
204 % |\raggedright| cannot be overridden later and should therefore
205 % be used in the |plain| style with great care.
206 %
207 % \section{To do}
208 %
209 % \begin{itemize}
210 % \item
211 % Further testing
212 % \item
213 % Improving the documentation, in particular including a section
214 % with usage examples
215 % \item
216 % Implementing some frame and color features
217 % \end{itemize}
218 %
219 % \section{Implementation}
220 %
221 % \begin{macrocode}
222 \newlength\@GenMPparindent
223
224 \def\@iiiminipage#1#2[#3]#4{%
225 \@ifnextchar[%
226 {\@ivminipage{#1}{#2}{#3}{#4}}
227 {\@ivminipage{#1}{#2}{#3}{#4}[]}}
228
229 \def\@ivminipage#1#2#3#4[#5]{%
230 \setkeys{GenMP}{plain,#5}%
231 \if@GenMPwidth\else\@GenMPwidth#4\fi
232 \if@GenMPheight\else
233 \def\@GenMPtempa{#2}\def\@GenMPtempb{\relax}%
234 \ifx\@GenMPtempa\@GenMPtempb%
235 \let\@GenMPheight=\relax
236 \else
237 \def\@GenMPheight{#2}%
238 \fi
239 \fi
240 \if@GenMPouter\else\def\@GenMPouter{#1}\fi%
241 \if@GenMPinner\else\def\@GenMPinner{#3}\fi%
242 \@GenMPparindent\parindent
243 \leavevmode
244 \@pboxswfalse
245 \@tempdima\@GenMPwidth
246 \def\@mpargs{{\@GenMPouter}{\@GenMPheight}[\@GenMPinner]{\@GenMPwidth}}%
247 \setbox\@tempboxa\vbox\bgroup
248 \color@begingroup
249 \hsize\@tempdima
250 \textwidth\hsize \columnwidth\hsize
251 \@parboxrestore
252 \def\@mpfn{mpfootnote}\def\thempfn{\thempfootnote}\c@mpfootnote\z@
253 \let\@footnotetext\@mpfootnotetext
254 \let\@listdepth\@mplistdepth \@mplistdepth\z@
255 \@minipagerestore
256 \@setminipage}
257
258 \def\@setminipage{%
259 \@minipagetrue
260 \@GenMPtop
261 \@GenMPflush
262 \@GenMPresetfont
263 \@GenMPffamily\@GenMPfseries\@GenMPfshape\selectfont
264 \@GenMPfsize
265 \@GenMPsetpi
266 \everypar{\@minipagefalse\everypar{}}}
267
268 \let\@GenMPendminipage\endminipage
269 \def\endminipage{%
270 \@GenMPbottom
271 \@GenMPendminipage}
272
273 \let\@GenMPflush=\relax
274 \define@key{GenMP}{flush}[]{\let\@GenMPflush=\relax}
275 \define@key{GenMP}{raggedright}[]{\let\@GenMPflush=\raggedright}
276 \define@key{GenMP}{RaggedRight}[]{\let\@GenMPflush=\RaggedRight}
277 \define@key{GenMP}{raggedleft}[]{\let\@GenMPflush=\raggedleft}
278 \define@key{GenMP}{center}[]{\let\@GenMPflush=\centering}
279
280 \let\@GenMPffamily=\relax
281 \let\@GenMPfseries=\relax
282 \let\@GenMPfshape=\relax
283 \let\@GenMPresetfont=\relax
284 \let\@GenMPfsize=\relax
285 \define@key{GenMP}{ffamily}{\def\@GenMPffamily{\fontfamily{#1}}}
286 \define@key{GenMP}{fseries}{\def\@GenMPfseries{\fontseries{#1}}}
287 \define@key{GenMP}{fshape}{\def\@GenMPfshape{\fontshape{#1}}}
288 \define@key{GenMP}{resetfont}[true]{%
289 \def\@GenMPread{#1}\def\@GenMPtempa{true}%
290 \ifx\@GenMPread\@GenMPtempa%
291 \let\@GenMPresetfont=\normalfont
292 \else
293 \let\@GenMPresetfont=\relax
294 \fi}
295 \define@key{GenMP}{fsize}{\def\@GenMPfsize{\csname #1\endcsname}}
296
297 \let\@GenMPsetpi=\relax
298 \define@key{GenMP}{keepparindent}[true]{%
299 \def\@GenMPread{#1}\def\@GenMPtempa{true}%
300 \ifx\@GenMPread\@GenMPtempa%
301 \def\@GenMPsetpi{\parindent\@GenMPparindent}%
302 \fi}
303 \define@key{GenMP}{parindent}{\def\@GenMPsetpi{\parindent#1}}
304
305 \newlength\@GenMPwidth
306 \newif\if@GenMPwidth
307 \let\if@GenMPwidth\iffalse
308 \define@key{GenMP}{width}{\let\if@GenMPwidth\iftrue\@GenMPwidth#1}
309 \define@key{GenMP}{widtharg}[]{\let\if@GenMPwidth\iffalse}
310 \newif\if@GenMPheight
311 \let\if@GenMPheight\iffalse
312 \define@key{GenMP}{height}{\let\if@GenMPheight\iftrue\def\@GenMPheight{#1}}
313 \define@key{GenMP}{heightarg}[]{\let\if@GenMPheight\iffalse}
314
315 \newif\if@GenMPouter
316 \let\if@GenMPouter\iffalse
317 \let\@GenMPtop=\relax
318 \let\@GenMPbottom=\relax
319 \define@key{GenMP}{outer}{%
320 \def\@GenMPread{#1}\def\@GenMPtempa{T}%
321 \ifx\@GenMPread\@GenMPtempa%
322 \def\@GenMPtop{\vspace{0pt}}%
323 \def\@GenMPouter{t}%
324 \else
325 \def\@GenMPtempa{B}%
326 \ifx\@GenMPread\@GenMPtempa%
327 \def\@GenMPbottom{\vspace{0pt}}%
328 \def\@GenMPouter{b}%
329 \else
330 \def\@GenMPouter{#1}%
331 \fi
332 \fi
333 \let\if@GenMPouter\iftrue
334 }
335 \define@key{GenMP}{outerarg}[]{\let\if@GenMPouter\iffalse}
336
337 \newif\if@GenMPinner
338 \let\if@GenMPinner\iffalse
339 \define@key{GenMP}{inner}{\let\if@GenMPinner\iftrue\def\@GenMPinner{#1}}
340 \define@key{GenMP}{innerarg}[]{\let\if@GenMPinner\iffalse}
341
342 \def\defineMPstyle#1#2{%
343 \define@key{GenMP}{#1}[]{\setkeys{GenMP}{#2}}}
344
345 \defineMPstyle{plain}{}
346 % \end{macrocode}
347 %
348 % \Finale
349 %
350 \endinput
351 %
352 % end of file `genmpage.dtx'