Browse Source

color safe; no reboxing

tags/1.2
Jonathan Spratte 2 years ago
parent
commit
336e5da0af
2 changed files with 49 additions and 29 deletions
  1. 49
    29
      grabbox.dtx
  2. BIN
      grabbox.pdf

+ 49
- 29
grabbox.dtx View File

@@ -136,10 +136,10 @@ and the derived files           grabbox.pdf and
136 136
 %   register}. The box is of \meta{box type}, which should be one of \cs{hbox}
137 137
 %   or \cs{vbox} or \cs{vtop}. \meta{inject pre} will be injected at the
138 138
 %   beginning of the box and can affect its contents, \meta{inject post} will be
139
-%   injected after the box but can't be affected by stuff inside of \meta{inject
140
-%   pre}. Unless the \meta{*} is given leading and trailing spaces will be
141
-%   stripped from the box. After the box is read in \meta{afterwards} will be
142
-%   inserted.
139
+%   injected at the end of the box but can't be affected by stuff inside of
140
+%   \meta{inject pre} or added content unless they are using global definitions.
141
+%   Unless the \meta{*} is given leading and trailing spaces will be stripped
142
+%   from the box. After the box is read in \meta{afterwards} will be inserted.
143 143
 % \end{function}
144 144
 %
145 145
 %   \smallskip
@@ -282,31 +282,38 @@ and the derived files           grabbox.pdf and
282 282
 %
283 283
 %    \begin{macrocode}
284 284
 \@ifdefinable{\if@grabbox@spaces@}{\newif\if@grabbox@spaces@}
285
-\newcommand\grabbox@def[2]
285
+
286
+\@ifdefinable{\grabbox@def}{\long\def\grabbox@def#1#2#{\grabbox@def@a{#1}{#2}}}
287
+\@ifdefinable{\grabbox@def@a}
286 288
   {%
287
-    \@ifdefinable#1{\protected\def#1{#2}}%
289
+    \protected\long\def\grabbox@def@a#1#2#3%
290
+      {\@ifdefinable#1{\protected\def#1#2{#3}}}%
288 291
   }
289 292
 \newcommand\grabbox@def@step[4]
290 293
   {%
291
-    \@ifdefinable#1{\protected\def#1##1{\def#2{##1}\grabbox@opt#3#4}}%
294
+    \@ifdefinable#1{\grabbox@def#1##1{\def#2{##1}\grabbox@opt#3#4}}%
292 295
   }
296
+\long\def\grabbox@afterelsefi#1\else#2\fi{\fi#1}
297
+\long\def\grabbox@afterfi#1\fi{\fi#1}
298
+\long\def\grabbox@afterelsefiA\else#1\fi#2#3{\fi#2}
299
+\long\def\grabbox@afterfiB\fi#1#2{\fi#2}
293 300
 \long\def\grabbox@check@bracket #1[#2\endgrabbox@check@bracket
294 301
   {%
295 302
     \if\relax\detokenize{#2}\relax
296
-      \expandafter\@firstoftwo
303
+      \grabbox@afterelsefiA
297 304
     \else
298
-      \expandafter\@secondoftwo
305
+      \grabbox@afterfiB
299 306
     \fi
300 307
   }
301
-\protected\def\grabbox@opt#1#2%
308
+\grabbox@def\grabbox@opt#1#2%
302 309
   {%
303 310
     \@ifnextchar[
304 311
       {\grabbox@opt@get#1#2}
305 312
       {\def#1{}#2}%
306 313
   }
307
-\long\def\grabbox@opt@get#1#2#3]%
314
+\long\def\grabbox@opt@get#1#2[#3]%
308 315
   {%
309
-    \expandafter\grabbox@opt@get@a\expandafter{\@gobble#3}#1#2%
316
+    \grabbox@opt@get@a{#3}#1#2%
310 317
   }
311 318
 \protected\long\def\grabbox@opt@get@a#1#2#3%
312 319
   {%
@@ -324,15 +331,13 @@ and the derived files           grabbox.pdf and
324 331
   {%
325 332
     \begingroup
326 333
     \edef\grabbox@test{\grabbox@type}%
327
-    \expandafter\ifx\grabbox@type\hbox
334
+    \expandafter\ifx\grabbox@test\hbox
328 335
       \endgroup
329
-      \expandafter\@firstoftwo
336
+      \grabbox@afterelsefi\unhbox
330 337
     \else
331 338
       \endgroup
332
-      \expandafter\@secondoftwo
339
+      \grabbox@afterfi\unvbox
333 340
     \fi
334
-    \unhbox
335
-    \unvbox
336 341
     \grabbox@name
337 342
   }
338 343
 \grabbox@def\grabbox
@@ -349,8 +354,21 @@ and the derived files           grabbox.pdf and
349 354
     \afterassignment\grabbox@intermediate
350 355
     \setbox\grabbox@name\grabbox@type
351 356
   }
357
+\grabbox@def\grabbox@set@color
358
+  {%
359
+    \@ifundefined{set@color}{}
360
+      {\global\let\grabbox@set@color\set@color\grabbox@set@color}%
361
+  }
362
+\AtBeginDocument
363
+  {%
364
+    \@ifundefined{set@color}
365
+      {\gdef\grabbox@set@color{}}
366
+      {\global\let\grabbox@set@color\set@color}%
367
+  }%
352 368
 \grabbox@def\grabbox@intermediate
353 369
   {%
370
+    \bgroup
371
+    \grabbox@set@color
354 372
     \aftergroup\grabbox@after
355 373
     \grabbox@into@pre
356 374
     \if@grabbox@spaces@
@@ -358,23 +376,25 @@ and the derived files           grabbox.pdf and
358 376
       \ignorespaces
359 377
     \fi
360 378
   }
379
+\newcommand*\grabbox@after@aux@b[1]
380
+  {%
381
+    \grabbox@after@aux@a
382
+  }
383
+\grabbox@def\grabbox@after@aux@a
384
+  {%
385
+    \@ifnextchar\reset@color
386
+      {\reset@color\grabbox@after@aux@b}
387
+      {\egroup\grabbox@final}%
388
+  }
361 389
 \grabbox@def\grabbox@after
362 390
   {%
363 391
     \if@grabbox@spaces@
364
-      \setbox\grabbox@name\grabbox@type
365
-        {%
366
-          \grabbox@unpack
367
-          \grabbox@into@post
368
-        }%
369 392
     \else
370
-      \setbox\grabbox@name\grabbox@type
371
-        {%
372
-          \grabbox@unpack
373
-          \ifhmode\unskip\fi
374
-          \grabbox@into@post
375
-        }%
393
+      \ifhmode\unskip\fi
376 394
     \fi
377
-    \grabbox@final
395
+    \grabbox@into@post
396
+    \endgraf
397
+    \grabbox@after@aux@a
378 398
   }
379 399
 %    \end{macrocode}
380 400
 %

BIN
grabbox.pdf View File


Loading…
Cancel
Save