|
@@ -60,15 +60,18 @@ and the derived files grabbox.pdf and
|
60
|
60
|
\csname grabbox@date\endcsname\
|
61
|
61
|
utilities to get an argument as a box%
|
62
|
62
|
]
|
|
63
|
+\expandafter\def\csname @classoptionslist\endcsname{}
|
|
64
|
+\RequirePackage[british]{babel}
|
63
|
65
|
\documentclass{l3doc}
|
64
|
66
|
\usepackage{duckuments}
|
|
67
|
+\usepackage{microtype}
|
65
|
68
|
\usepackage{grabbox}
|
66
|
|
-\author{Jonathan P. Spratte\thanks{Email: jspratte@yahoo.de}}
|
67
|
|
-\title{The \pkg{grabbox} package}
|
68
|
|
-\makeatletter
|
69
|
|
-\date{\grabbox@date\ v\grabbox@version}
|
70
|
69
|
\renewcommand*{\thefootnote}{\fnsymbol{footnote}}
|
71
|
|
-\makeatother
|
|
70
|
+\let\metaOrig\meta
|
|
71
|
+\renewcommand\meta[1]
|
|
72
|
+ {%
|
|
73
|
+ \texttt{\metaOrig{#1}}%
|
|
74
|
+ }
|
72
|
75
|
\begin{document}
|
73
|
76
|
\DocInput{grabbox.dtx}
|
74
|
77
|
\end{document}
|
|
@@ -97,6 +100,12 @@ and the derived files grabbox.pdf and
|
97
|
100
|
%
|
98
|
101
|
% \section{Introduction}
|
99
|
102
|
%
|
|
103
|
+% Sometimes I happen to write macros and environments which don't care for the
|
|
104
|
+% exact contents of an argument but only for that contents typeset
|
|
105
|
+% representation and its dimensions. In that case I personally dislike the fact
|
|
106
|
+% that those arguments couldn't contain verbatim material if coded straight
|
|
107
|
+% forward. Thus the macros distributed hereby came into existence.
|
|
108
|
+%
|
100
|
109
|
% This package provides \cs{grabbox} to grab an argument inside of a box. The
|
101
|
110
|
% used mechanism allows category code changes in that argument as long as it is
|
102
|
111
|
% used in a place allowing category code changes (so not inside of another
|
|
@@ -105,40 +114,41 @@ and the derived files grabbox.pdf and
|
105
|
114
|
% It is written as a docstrip file: executing |latex grabbox.dtx| generates the
|
106
|
115
|
% \file{grabbox.sty} file and typesets this documentation; execute
|
107
|
116
|
% |tex grabbox.dtx| to only generate \file{grabbox.sty}.
|
|
117
|
+%
|
|
118
|
+% \section{Acknowledgement}
|
|
119
|
+%
|
|
120
|
+% I want to thank Enrico Gregorio for helping me develop first versions of the
|
|
121
|
+% used mechanisms for the second iteration of my \pkg{ducksay} package. If he
|
|
122
|
+% hadn't helped me back then, I wouldn't have considered the used method further
|
|
123
|
+% and therefore this package wouldn't have been created.
|
108
|
124
|
%
|
109
|
125
|
% \section{The macro}
|
110
|
126
|
%
|
111
|
127
|
% \begin{function}{\grabbox}
|
112
|
128
|
% \begin{syntax}
|
113
|
|
-% \cs{grabbox}\meta{*}
|
114
|
|
-% \marg{box register}\oarg{inject pre}\marg{box type}\oarg{inject post}
|
115
|
|
-% \marg{next}\oarg{save args}
|
|
129
|
+% \cs{grabbox}\meta{*}\marg{box register}\ignorespaces^^A
|
|
130
|
+% \oarg{inject pre}\marg{box type}\oarg{inject post}\ignorespaces^^A
|
|
131
|
+% \marg{next}
|
116
|
132
|
% \end{syntax}
|
117
|
|
-% Grabs the next braced argument inside of the box \meta{box register}. The
|
118
|
|
-% box is of \meta{box type}, which should be one of \cs{hbox} or \cs{vbox} or
|
119
|
|
-% \cs{vtop}. \meta{inject pre} will be injected at the beginning of the box
|
120
|
|
-% and can affect its contents, \meta{inject post} will be injected after the
|
121
|
|
-% box but can't be affected by stuff inside of \meta{inject pre}. Unless the
|
122
|
|
-% \meta{*} is given leading and trailing spaces will be stripped from the box.
|
123
|
|
-% After the box is read in \meta{next} will be executed. The usage is
|
124
|
|
-% therefore similar to the one of \cs{@ifstar}. You can specify arguments
|
125
|
|
-% which should be given to \meta{next} using \meta{save args}. The stuff you
|
126
|
|
-% provide in \meta{save args} will be given as is to \meta{next}, so if you
|
127
|
|
-% want to give an argument you should delimit it with braces, like
|
128
|
|
-% \verb|[{#1}]|, or if you want to give two arguments, like
|
129
|
|
-% \verb|[{#1}{#2}]|.
|
|
133
|
+% grabs the next braced argument and stores it inside of the box \meta{box
|
|
134
|
+% register}. The box is of \meta{box type}, which should be one of \cs{hbox}
|
|
135
|
+% or \cs{vbox} or \cs{vtop}. \meta{inject pre} will be injected at the
|
|
136
|
+% beginning of the box and can affect its contents, \meta{inject post} will be
|
|
137
|
+% injected after the box but can't be affected by stuff inside of \meta{inject
|
|
138
|
+% pre}. Unless the \meta{*} is given leading and trailing spaces will be
|
|
139
|
+% stripped from the box. After the box is read in \meta{next} will be
|
|
140
|
+% inserted.
|
130
|
141
|
% \end{function}
|
131
|
142
|
%
|
132
|
143
|
% \smallskip
|
133
|
144
|
% All assignments are made local. Currently it is not safe to nest macros
|
134
|
|
-% which use \cs{grabbox}. It should become save if you're macros use
|
135
|
|
-% \cs{grabbox} inside of a group, so the local assignments don't affect the
|
136
|
|
-% outer macro.
|
|
145
|
+% which use \cs{grabbox}. It should become save if your macros use
|
|
146
|
+% \cs{grabbox} inside of a group, so the inner \cs{grabbox} doesn't affect the
|
|
147
|
+% outer one.
|
137
|
148
|
%
|
138
|
149
|
% \cs{grabbox} uses \cs{afterassignment} and \cs{aftergroup} to do its magic.
|
139
|
|
-% The \cs{afterassignment} should be safe where it is used, the
|
140
|
|
-% \cs{aftergroup} is used inside of the boxed argument before any contents are
|
141
|
|
-% inserted.
|
|
150
|
+% The former should be safe where it is used, the latter is used inside of the
|
|
151
|
+% boxed argument before any contents are inserted.
|
142
|
152
|
%
|
143
|
153
|
% Since \cs{grabbox} works by setting a boxregister using \cs{setbox} (and a
|
144
|
154
|
% bunch of temporary macros), it is of course not expandable and defined
|
|
@@ -153,13 +163,13 @@ and the derived files grabbox.pdf and
|
153
|
163
|
% \newsavebox\ourbox
|
154
|
164
|
% \end{verbatim}
|
155
|
165
|
%
|
156
|
|
-% Next we define a macro which takes some arguments and uses our macro:
|
|
166
|
+% Next we define a macro which takes some arguments and uses \cs{grabbox}:
|
157
|
167
|
%
|
158
|
168
|
% \begin{verbatim}
|
159
|
169
|
% \newcommand\examplecmd[2]
|
160
|
170
|
% {%
|
161
|
171
|
% \begingroup
|
162
|
|
-% \grabbox\ourbox[\itshape]\hbox[ \sffamily is]\examplecmdOut[{#1}{#2}]
|
|
172
|
+% \grabbox\ourbox[\itshape]\hbox[ \sffamily is]{\examplecmdOut{#1}{#2}}
|
163
|
173
|
% }
|
164
|
174
|
% \end{verbatim}
|
165
|
175
|
%
|
|
@@ -186,7 +196,7 @@ and the derived files grabbox.pdf and
|
186
|
196
|
% \newcommand\examplecmd[2]
|
187
|
197
|
% {%
|
188
|
198
|
% \begingroup
|
189
|
|
-% \grabbox\ourbox[\itshape]\hbox[ \sffamily is]\examplecmdOut[{#1}{#2}]
|
|
199
|
+% \grabbox\ourbox[\itshape]\hbox[ \sffamily is]{\examplecmdOut{#1}{#2}}
|
190
|
200
|
% }%
|
191
|
201
|
% \newcommand\examplecmdOut[3]
|
192
|
202
|
% {%
|
|
@@ -200,9 +210,8 @@ and the derived files grabbox.pdf and
|
200
|
210
|
% }%
|
201
|
211
|
% \examplecmd{Hi,}{my}{\verb|name|}{Steve!}
|
202
|
212
|
% \end{center}
|
203
|
|
-% One can see that the \verb|\sffamily is| of \meta{inject post} is not affected
|
204
|
|
-% by the |\itshape| in \meta{inject pre}. The used code to generate that table
|
205
|
|
-% was:
|
|
213
|
+% One can see that \verb|\sffamily is| of \meta{inject post} is not affected by
|
|
214
|
+% the |\itshape| in \meta{inject pre}. The used code to generate that table was:
|
206
|
215
|
%
|
207
|
216
|
% \begin{verbatim}
|
208
|
217
|
% \examplecmd{Hi,}{my}{\verb|name|}{Steve!}
|
|
@@ -216,20 +225,21 @@ and the derived files grabbox.pdf and
|
216
|
225
|
% \begin{verbatim}
|
217
|
226
|
% % Getting a box register:
|
218
|
227
|
% \newsavebox\RectangleBox
|
219
|
|
-% % Defining the main macro
|
|
228
|
+% % Defining the main macro:
|
220
|
229
|
% \newcommand\Rectangle[1][4]
|
221
|
230
|
% {%
|
222
|
231
|
% \begingroup
|
223
|
|
-% \grabbox\RectangleBox\hbox\RectangleOut[{#1}]
|
224
|
|
-% }
|
225
|
|
-% % Defining the secondary macro
|
226
|
|
-% \newcommand\RectangleOut[1]
|
227
|
|
-% {%
|
228
|
|
-% \begin{minipage}{\dimexpr\wd\RectangleBox/#1\relax}
|
229
|
|
-% \parfillskip0pt
|
230
|
|
-% \unhbox\RectangleBox
|
231
|
|
-% \end{minipage}%
|
232
|
|
-% \endgroup
|
|
232
|
+% \grabbox\RectangleBox\hbox
|
|
233
|
+% {%
|
|
234
|
+% % Since we don't want to read more arguments after the box,
|
|
235
|
+% % we don't need a second macro and can put the output routine
|
|
236
|
+% % here.
|
|
237
|
+% \begin{minipage}{\dimexpr\wd\RectangleBox/#1\relax}
|
|
238
|
+% \parfillskip0pt
|
|
239
|
+% \unhbox\RectangleBox
|
|
240
|
+% \end{minipage}%
|
|
241
|
+% \endgroup
|
|
242
|
+% }%
|
233
|
243
|
% }
|
234
|
244
|
% \end{verbatim}
|
235
|
245
|
%
|
|
@@ -245,22 +255,21 @@ and the derived files grabbox.pdf and
|
245
|
255
|
% \Rectangle[9]{\blindduck}
|
246
|
256
|
% \end{center}
|
247
|
257
|
% \end{verbatim}
|
248
|
|
-% Results:
|
|
258
|
+% Results in:
|
|
259
|
+% \begin{center}
|
249
|
260
|
% \newsavebox\RectangleBox
|
250
|
261
|
% \newcommand\Rectangle[1][4]
|
251
|
262
|
% {%
|
252
|
263
|
% \begingroup
|
253
|
|
-% \grabbox\RectangleBox\hbox\RectangleOut[{#1}]
|
254
|
|
-% }%
|
255
|
|
-% \newcommand\RectangleOut[1]
|
256
|
|
-% {%
|
257
|
|
-% \begin{minipage}{\dimexpr\wd\RectangleBox/#1\relax}
|
258
|
|
-% \parfillskip0pt
|
259
|
|
-% \unhbox\RectangleBox
|
260
|
|
-% \end{minipage}%
|
261
|
|
-% \endgroup
|
262
|
|
-% }%
|
263
|
|
-% \begin{center}
|
|
264
|
+% \grabbox\RectangleBox\hbox
|
|
265
|
+% {%
|
|
266
|
+% \begin{minipage}{\dimexpr\wd\RectangleBox/#1\relax}
|
|
267
|
+% \parfillskip0pt
|
|
268
|
+% \unhbox\RectangleBox
|
|
269
|
+% \end{minipage}%
|
|
270
|
+% \endgroup
|
|
271
|
+% }%
|
|
272
|
+% }
|
264
|
273
|
% \Rectangle[9]{\blindduck}
|
265
|
274
|
% \end{center}
|
266
|
275
|
%
|
|
@@ -276,7 +285,6 @@ and the derived files grabbox.pdf and
|
276
|
285
|
%
|
277
|
286
|
% \begin{macrocode}
|
278
|
287
|
\@ifdefinable{\if@grabbox@spaces@}{\newif\if@grabbox@spaces@}
|
279
|
|
-\newcommand*\grabbox@args{}%
|
280
|
288
|
\newcommand\grabbox@def[2]
|
281
|
289
|
{%
|
282
|
290
|
\@ifdefinable#1{\protected\def#1{#2}}%
|
|
@@ -334,9 +342,9 @@ and the derived files grabbox.pdf and
|
334
|
342
|
}
|
335
|
343
|
\grabbox@def@step\grabbox@a\grabbox@name\grabbox@into@pre\grabbox@b
|
336
|
344
|
\grabbox@def@step\grabbox@b\grabbox@type\grabbox@into@post\grabbox@c
|
337
|
|
-\grabbox@def@step\grabbox@c\grabbox@final\grabbox@args\grabbox@d
|
338
|
|
-\grabbox@def\grabbox@d
|
|
345
|
+\protected\long\def\grabbox@c#1%
|
339
|
346
|
{%
|
|
347
|
+ \def\grabbox@final{#1}%
|
340
|
348
|
\afterassignment\grabbox@intermediate
|
341
|
349
|
\setbox\grabbox@name\grabbox@type
|
342
|
350
|
}
|
|
@@ -361,12 +369,7 @@ and the derived files grabbox.pdf and
|
361
|
369
|
\grabbox@into@post
|
362
|
370
|
}%
|
363
|
371
|
\fi
|
364
|
|
- \expandafter\grabbox@final@exp@args\expandafter{\grabbox@args}%
|
365
|
|
- }
|
366
|
|
-\newcommand\grabbox@final@exp@args[1]
|
367
|
|
- {%
|
368
|
|
- \def\grabbox@args{}%
|
369
|
|
- \grabbox@final#1%
|
|
372
|
+ \grabbox@final
|
370
|
373
|
}
|
371
|
374
|
% \end{macrocode}
|
372
|
375
|
%
|