collectbox.sty (9116B)
1 %% 2 %% This is file `collectbox.sty', 3 %% generated with the docstrip utility. 4 %% 5 %% The original source files were: 6 %% 7 %% collectbox.dtx (with options: `collectbox.sty') 8 %% 9 %% IMPORTANT NOTICE: 10 %% 11 %% For the copyright see the source file. 12 %% 13 %% Any modified versions of this file must be renamed 14 %% with new filenames distinct from collectbox.sty. 15 %% 16 %% For distribution of the original source see the terms 17 %% for copying and modification in the file collectbox.dtx. 18 %% 19 %% This generated file may be distributed as long as the 20 %% original source files, as listed above, are part of the 21 %% same distribution. (The sources need not necessarily be 22 %% in the same archive or directory.) 23 %% Copyright (C) 2012 by Martin Scharrer <martin@scharrer-online.de> 24 %% -------------------------------------------------------------------- 25 %% This work may be distributed and/or modified under the 26 %% conditions of the LaTeX Project Public License, either version 1.3 27 %% of this license or (at your option) any later version. 28 %% The latest version of this license is in 29 %% http://www.latex-project.org/lppl.txt 30 %% and version 1.3 or later is part of all distributions of LaTeX 31 %% version 2005/12/01 or later. 32 %% 33 %% This work has the LPPL maintenance status `maintained'. 34 %% 35 %% The Current Maintainer of this work is Martin Scharrer. 36 %% 37 %% This work consists of the files collectbox.dtx and collectbox.ins 38 %% and the derived filebase collectbox.sty. 39 %% 40 \NeedsTeXFormat{LaTeX2e}[1999/12/01] 41 \ProvidesPackage{collectbox}[% 42 2012/05/17 43 v0.4b 44 Collect macro arguments as boxes] 45 \newsavebox\collectedbox 46 \newcommand*\collectbox{% 47 \@ifstar 48 {\collectbox@a{{\BOXCONTENT}}}% 49 {\collectbox@a{}}% 50 } 51 \long\def\collectbox@a#1{% 52 \@ifnextchar[% 53 {\collectbox@b{#1}}% 54 {\collectbox@b{#1}[]}% 55 } 56 \long\def\collectbox@b#1[#2]#3{% 57 \@ifnextchar[% 58 {\collectbox@c{#2}{#3#1}}% 59 {\collectbox@c{#2}{#3#1}[]}% 60 } 61 \long\def\collectbox@c#1#2[#3]{% 62 \collectbox@{#1}{#2}{#3}% 63 } 64 \let\collect@box\hbox 65 \let\collectbox@mode\leavevmode 66 \newcommand\collectbox@[3]{% 67 \begingroup 68 \collectbox@mode 69 \@temptokena{#3\collectbox@end#2\endgroup}% 70 \setbox\collectedbox\collect@box\bgroup 71 \collectbox@setgroup 72 #1\bgroup 73 \aftergroup\the 74 \aftergroup\@temptokena 75 \collectbox@bgroup 76 } 77 \let\collectbox@macro\collectbox@ 78 \newcommand\collectbox@env[3]{% 79 \collectbox@mode 80 \def\collectboxenvend{#3\collectbox@end#2\collectbox@currenvir}% 81 \setbox\collectedbox\collect@box\bgroup 82 \collectbox@setgroup 83 \collectbox@reset 84 \ignorespaces 85 #1% 86 } 87 \def\collectbox@currenvir{% 88 \edef\@currenvir{\@currenvir}% 89 } 90 \def\collectbox@macro@bgroup{% 91 \@ifnextchar\bgroup 92 {\let\@let@token=}% 93 {\collectbox@arg}% 94 } 95 \def\collectbox@env@bgroup{% 96 \collectbox@reset 97 \ignorespaces 98 } 99 \let\collectbox@bgroup\collectbox@macro@bgroup 100 \def\collectbox@setgroup{% 101 \color@setgroup 102 } 103 \def\collectbox@endgroup{% 104 \collectbox@endcode 105 \color@endgroup 106 } 107 \let\collectbox@endcode\relax 108 \newcommand\@collectbox[1]{% 109 \begingroup 110 \collectbox@mode 111 \@temptokena{\collectbox@end#1\endgroup}% 112 \setbox\collectedbox\collect@box\bgroup 113 \collectbox@setgroup\bgroup 114 \aftergroup\the 115 \aftergroup\@temptokena 116 \collectbox@bgroup 117 } 118 \newcommand\@Collectbox[2]{% 119 \begingroup 120 \collectbox@mode 121 \sbox\collectedbox{#2}% 122 \collectbox@setdims 123 #1% 124 \endgroup 125 } 126 \def\collectbox@arg#1{% 127 #1\egroup 128 } 129 \def\collectbox@end{% 130 \collectbox@endgroup 131 \egroup 132 \collectbox@setdims 133 \ifcollectboxenv 134 \collectbox@reset 135 \collectbox@currenvir 136 \fi 137 } 138 \def\collectbox@setdims{% 139 \collectbox@protecteddef\BOXCONTENT{\usebox\collectedbox}% 140 \collectbox@protecteddef\width{\wd\collectedbox}% 141 \collectbox@protecteddef\height{\ht\collectedbox}% 142 \collectbox@protecteddef\depth{\dp\collectedbox}% 143 \collectbox@protecteddef\totalheight{\@ovri}% 144 \totalheight\height 145 \advance\totalheight\depth 146 }% 147 \def\collectbox@reset{% 148 \let\collectbox@endcode\relax 149 \let\collectbox@bgroup\collectbox@macro@bgroup 150 \let\collectbox@\collectbox@macro 151 \collectboxenvfalse 152 } 153 \begingroup 154 \expandafter\ifx\csname protected\endcsname\relax 155 \let\collectbox@protecteddef\def% 156 \else 157 \gdef\collectbox@protecteddef{\protected\def}% 158 \fi 159 \endgroup 160 \let\collectbox@code\empty 161 \newcommand\collectboxto[1]{% 162 \@ifnextchar[% 163 {\collectboxto@a{#1}}% 164 {\collectboxto@a{#1}[]}% 165 } 166 \long\def\collectboxto@a#1[#2]#3{% 167 \@ifnextchar[% 168 {\collectboxto@b{#1}{#2}{#3}}% 169 {\collectboxto@b{#1}{#2}{#3}[]}% 170 } 171 \long\def\collectboxto@b#1#2#3[#4]{% 172 \collectboxto@{#1}{#2}{#3}{#4}% 173 } 174 \newcommand\collectboxto@[4]{% 175 \collectbox@mode 176 \setbox#1\collect@box\bgroup 177 \def\collectbox@code{#4\collectbox@endgroup\egroup#3}% 178 \collectbox@setgroup#2\bgroup 179 \aftergroup\collectbox@code 180 \collectbox@bgroup 181 } 182 \newcommand\@collectboxto[2]{% 183 \collectbox@mode 184 \setbox#1\collect@box\bgroup 185 \def\collectbox@code{\collectbox@endgroup\egroup#2}% 186 \collectbox@setgroup\bgroup 187 \aftergroup\collectbox@code 188 \collectbox@bgroup 189 } 190 \newcommand\nocollectbox@[3]{% 191 \collectbox@mode 192 \collect@box\bgroup 193 \def\collectbox@code{#3\egroup#2}% 194 #1\bgroup 195 \aftergroup\collectbox@code 196 \collectbox@bgroup 197 } 198 \newcommand\nocollectbox@to[4]{% 199 \collectbox@mode 200 \collect@box to #1\bgroup 201 \def\collectbox@code{#4\egroup#3}% 202 #2\bgroup 203 \aftergroup\collectbox@code 204 \collectbox@bgroup 205 } 206 \newcommand*\collectboxcheckenv[1]{% 207 \begingroup 208 \def\@tempa{#1}% 209 \expandafter\endgroup 210 \ifx\@currenvir\@tempa 211 \@collectboxisenv{#1}% 212 \fi 213 } 214 \def\@collectboxisenv#1{% 215 \collectbox@noindent 216 \collectboxenvtrue 217 \edef\@currenvir{\@currenvir\noexpand\empty}% 218 \let\collectbox@bgroup\collectbox@env@bgroup 219 \let\collectbox@endcode\collectbox@env@endcode 220 \let\collectbox@\collectbox@env 221 \expandafter\ifx\csname end#1\endcsname\relax 222 \expandafter\let\csname end#1\endcsname\collectbox@envend 223 \fi 224 } 225 \newif\ifcollectboxenv 226 \let\collectbox@noindent\noindent 227 \def\collectbox@env@endcode{\ifhmode\unskip\fi}% 228 \def\collectbox@envend{\collectboxenvend}% 229 \def\collectboxenvend{% 230 \egroup 231 \collectbox@currenvir 232 }% 233 \newcommand\collectboxtabular[3][c]{% 234 \collectbox@tab{tabular}{[#1]{#2}}{}{#3}{}% 235 } 236 \newcommand\collectboxtabularstar[4][c]{% 237 \collectbox@tab{tabular*}{[#1]{#2}{#3}}{}{#4}{}% 238 } 239 \newcommand\collectboxarray[2]{% 240 \collectbox@tab{array}{{#1}}{\(}{#2}{\)}% 241 } 242 \def\collectbox@checkarray{% 243 \@ifpackageloaded{array}{% 244 \let\collectbox@realarraycr\@arraycr 245 \def\collectbox@setarraycr{% 246 \let\@arraycr\collebox@cr 247 \def\ialign{\let\@arraycr\collectbox@realarraycr \everycr {}\tabskip \z@skip \halign}% 248 }% 249 }{% 250 \let\collectbox@realarraycr\@tabularcr 251 \def\collectbox@setarraycr{% 252 \let\@tabularcr\collebox@cr 253 \def\ialign{\let\noexpand\@tabularcr\noexpand\collectbox@realarraycr \everycr {}\tabskip \z@skip \halign}% 254 }% 255 }% 256 } 257 \collectbox@checkarray 258 \AtBeginDocument{\collectbox@checkarray}% 259 \def\collectbox@dorealarraycr{% 260 \expandafter\collectbox@realarraycr\collectbox@aftercrstuff 261 } 262 \let\collectbox@aftercrstuff\empty 263 \def\collectbox@tab#1#2#3#4#5{% 264 \begingroup 265 \collectbox@mode 266 \def\collectbox@codeafter{#4\endgroup}% 267 \def\collectbox@endtabenv{\end{#1}#5\collectbox@end}% 268 \def\collectbox@dotab{#3\begin{#1}#2}% 269 \setbox\collectedbox\collect@box\bgroup 270 \collectbox@setgroup 271 \collectbox@setarraycr 272 \afterassignment\collectbox@dotab 273 \let\@let@token=% 274 } 275 \def\collebox@cr{% 276 \@ifstar\collebox@@cr\collebox@@cr% 277 } 278 \def\collebox@@cr{% 279 \@ifnextchar[% 280 \collebox@@cr@opt 281 {\collebox@@@cr{}}% 282 } 283 \def\collebox@@cr@opt[#1]{% 284 \collebox@@@cr{[#1]}% 285 } 286 \def\collebox@@@cr#1{% 287 \def\collectbox@aftercrstuff{#1}% 288 \expandafter\collebox@@@@cr 289 \romannumeral-`0% 290 } 291 \def\collebox@@@@cr{% 292 \@ifnextchar\egroup{\collectbox@dorealarraycr\collectbox@aftertab}{% 293 \ifx\@let@token\noalign 294 \expandafter\collectbox@handlenoalign 295 \else 296 \expandafter\collectbox@dorealarraycr 297 \fi 298 }% 299 } 300 \def\collectbox@handlenoalign#1#2{% 301 \collectbox@dorealarraycr 302 \noalign{\bgroup\aftergroup\collectbox@afternoalign#2}% 303 } 304 \def\collectbox@handlenextnoalign#1#2{% 305 \egroup 306 \noalign{\bgroup\aftergroup\collectbox@afternoalign#2}% 307 } 308 \def\collectbox@afternoalign{% 309 \expandafter\collectbox@@afternoalign 310 \romannumeral-`0% 311 } 312 \def\collectbox@@afternoalign{% 313 \@ifnextchar\egroup{\egroup\collectbox@aftertab}{% 314 \ifx\@let@token\noalign 315 \expandafter\collectbox@handlenextnoalign 316 \else 317 \expandafter\egroup 318 \fi 319 }% 320 } 321 \def\collectbox@aftertab{% 322 \collectbox@endtabenv 323 \afterassignment\collectbox@codeafter 324 \let\@let@token=% 325 } 326 \endinput 327 %% 328 %% End of file `collectbox.sty'.